I'm learning Laravel from Lacast and i'm trying to create a CRUD application.I've implemented the index,show,create
and store
correctly,but with the edit
form when i try to submit data it's throwing BadMethodCallException
. Here are my routes
Route::get('/projects','ProjectsController@index');
Route::get('/projects/{id}','ProjectsController@show')->where('id','[0-9]+');
Route::get('/create','ProjectsController@create');
Route::post('/projects','ProjectsController@store');
Route::get('/projects/{id}/edit','ProjectsController@edit')->where('id','[0-9]+');
Route::put('/projects/{id}','ProjectsController@update')->where('id','[0-9]+');
Route::delete('/projects/{id}','ProjectsController@destroy');
Here is the edit
form:
@extends('template');
@section('content')
<h2>Create new project</h2>
<p>/projects/</p>
<form method="POST" action="/projects/">
<div>
<input value="" type="text" name="title" id="title" placeholder="Project title">
</div>
<div>
<textarea name="description" placeholder="Enter the project description"></textarea>
</div>
<div>
<button type="submit">Update project</button>
</div>
</form>
@endsection
The controller code:
public function edit($id){
$project= Project::find($id);
return view('projects.edit',compact('project'));
}
public function update($id){
$project= Project::find($id);
$project->title=request('title');
$project->description('description');
$project->save();
return redirect('/projects');
}
The edit form
displays as expected with data coming from the database,after submit i get the following error page:
With the example of the instructor the code has worked perfectly,and before using the PUT
either on my form and in my controller i used PATCH
like the instructor but always the same result.
Here is the instructor video link: Faking PATCH and DELETE Requests
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire