user2381011
user2381011

Reputation: 351

Laravel: delete photo by photo id

I'm trying to delete a photo by it's id, but the routes do not work and I receive a MethodNotAllowedHttpException. What I do:

First I create a form (in my blade template):

{{ Form::open(array("action" => array("cms/albums/destroyphoto", $photo['id']), "method" => "DELETE")) }}
    <button type="submit">Delete</button>
{{ Form::close() }}

Then i create my route:

Route::post('cms/albums/destroyphoto/{id}', 'AlbumsController@destroyphoto');

And create my function in the Albumscontroller:

public function destroyphoto($id)
{
    dd('Welcome photo');
}

Any suggestions where the routing goes wrong? Thanks in advance.

Ps. I did composer dump-autoload

Upvotes: 0

Views: 55

Answers (1)

lukasgeiter
lukasgeiter

Reputation: 152950

When you open your form using "action" you should pass the controller class and action name. You also don't need to specify the method since you're using Route::post

Like this:

{{ Form::open(array("action" => array("AlbumsController@destroyphoto", $photo['id']))) }}

More information

Upvotes: 2

Related Questions