Laravel 4.2 NotAllowedHttpException Method on Dispose

I'm new to Laravel, so I have a project, simple CRUD, but the delete method doesn't work when I try to delete data, and I really don't know why. This is mistake:

Mistake:

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");

      

+3


source to share


2 answers


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 can change your method to POST

and keep your route as it is, but to be RESTful it is best to go to DELETE

.

+5


source


I just figured out the answer, the error was on this line in the routes:

Route::delete('/project/destroy/{id}', "ProjectController@destroy");

      



The route method should be DELETE

0


source







All Articles