1
votes

I'm having the following resource route:

Route::resource('/evenementen', 'EventController');

According to the following command(php artisan route:list):

 POST      | admin/evenementen                    | evenementen.store   | App\Http\Controllers\EventController@store                             | web,App\Http\Middleware\isAdmin       |
 GET|HEAD  | admin/evenementen                    | evenementen.index   | App\Http\Controllers\EventController@index                             | web,App\Http\Middleware\isAdmin       |
 GET|HEAD  | admin/evenementen/create             | evenementen.create  | App\Http\Controllers\EventController@create                            | web,App\Http\Middleware\isAdmin       |
 GET|HEAD  | admin/evenementen/{evenementen}      | evenementen.show    | App\Http\Controllers\EventController@show                              | web,App\Http\Middleware\isAdmin       |
 DELETE    | admin/evenementen/{evenementen}      | evenementen.destroy | App\Http\Controllers\EventController@destroy                           | web,App\Http\Middleware\isAdmin       |
 PUT|PATCH | admin/evenementen/{evenementen}      | evenementen.update  | App\Http\Controllers\EventController@update                            | web,App\Http\Middleware\isAdmin       |
 GET|HEAD  | admin/evenementen/{evenementen}/edit | evenementen.edit    | App\Http\Controllers\EventController@edit                              | web,App\Http\Middleware\isAdmin  

I should have those routes. The store, index and create routes and methods are working. The rest of the routes are not.

If I got to /admin/evenementen/1/edit it gives me a "Page not found" error. This also happens if POST to /admin/evenementen/1 with the following form:

<form id="frm-delete" action="{{ URL::asset('admin/evenementen/'.$event->id) }}" method="POST">
    {{ csrf_field() }}
    @method('DELETE')
    <button type="submit" class="dropdown-item">
        Verwijderen
    </button>
</form>

In the EventController I have the following methods that should correspond with the routes:

public function index() {..}
public function destroy($id) {..}
public function show($id) {..}
public function create() {..}
public function store(CreateEventRequest $request) {..}
public function edit($id) {..}

Have been googling a lot and can't find what I am doing wrong. Really hope someone can help me out.

1
Your route is admin/evenementen while your form is calling admin/evenement.Magnus Eriksson
Yes that's a type but I did just now figure it out. I was passing $id to the method's but it should be the model instead of the ID. I updated the above typoGraham

1 Answers

2
votes

I couldn't wrap my mind about it and allready thought it was something simple.

If you create a resource the controller methods don't expect an ID but the model. So in my case with events

public function destroy($id) {..}

Should be:

public function destroy(Event $event) {..}

Really hopes this can help someone else out as well