i'm new with Laravel, so have a project, a simple CRUD, but the delete method is not working when i try to delete the data, and i don't really know why. This is the error:
Error:
throw new MethodNotAllowedHttpException($others);
Controller:
public function destroy($id)
{
$project = Project::find($id);
if($project->user_id==Auth::id()) {
$project->delete();
return Redirect::to('/');
} else {
Session::flash('message', 'You can't delete this!');
return Redirect::to('/');
}
}
View:
{{Form::open(array('url' => 'project/destroy/'.$p->id, 'method' => 'DELETE'))}}
{{Form::submit("Delete", array('class' => 't2tButton text-center'))}}
{{Form::close()}}
Routes:
Route::post('/project/destroy/{id}', "ProjectController@destroy");
You have a route set for POST
but not for DELETE
.
Try adding this to your routes:
Route::delete('/project/destroy/{id}', "ProjectController@destroy");
Or you could change your method to POST
and keep your route as is, but to keep it RESTful it's probably best to change to DELETE
.
I just figured out the answer, the error was on this line in Routes:
Route::delete('/project/destroy/{id}', "ProjectController@destroy");
the Route method needs to be DELETE
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.