Route:
Route::get('/projects/create', 'ProjectsController@create');
Route::post('/projects', 'ProjectsController@store');
Controller:
create
method
store
method
$project = new Project();
$project->title = request('title');
$project->description = request('decription');
$project->save();
return redirect('/projects');
View:
POST
, form action = /projects
edit
method with id param
$project = Project::find($id)
update
method with id param
$project->title = request('title');
$project->description = request('description');
$project->save();
return redirect('/projects');
value="{{ $project->title }}"
POST
, form action = /projects/{{ $project->id }}
@method('PATCH')
destroy
method, pass idProject::find($id)->delete();
return redirect('/projects');'
POST
, action = /projects/{{ $project->id }}
@method('DELETE')
@csrf
Blade directivefind()
method, we can use findOrFail()
, which will fail gracefully and present a 404 if the user passes an ID which doesn't exist in the db.