Reputation: 45
I have a route which has two parameters.
Route::delete('/org/{org-id}/delete/user/{user-id}', 'App\Http\Controllers\OrganizationController@deleteUserFromOrg')
->name('delete-user-from-org');
i call it in view
<td><a href="{{route('delete-user-from-org', ['org-id'=>$data->id, 'user-id' => $el->id ])}}"><button class="btn btn-danger">Удалить</button></a></td>
i think this should work because it substitutes the data correctly and redirects to the page http://localhost:8000/org/11/delete/user/2. REturn 404 error.
It's does not see the controller, I tried some function in the route itself, this does not work either.
Upvotes: 1
Views: 69
Reputation: 6393
Route::delete('/org/{org-id}/delete/user/{user-id}', 'App\Http\Controllers\OrganizationController@deleteUserFromOrg')
->name('delete-user-from-org');
look at the Route::delete()
part. In order to invoke that route i.e. delete-user-from-org
, you will require a DELETE request method (or create a form with a hidden input via @method('delete')
When you create a link with <a></a>, the request will be a GET (by default unless manipulated by js) which is why you are getting a 404 Not Found Error. You have two solutions.
<form action="{{route('delete-user-from-org',['org-id'=>$data->id, 'user-id' => $el->id ])}}" method="POST">
@method('DELETE')
...
</form>
fetch("{{route('delete-user-from-org',['org-id'=>$data->id, 'user-id' => $el->id ])}}", {
method: 'DELETE',
})
.then(res => res.text()) // or res.json()
.then(res => console.log(res))
Route::get('/org/{org-id}/delete/user/{user-id}', 'App\Http\Controllers\OrganizationController@deleteUserFromOrg')
->name('delete-user-from-org');
from Route::delete() to Route::get()
Upvotes: 2
Reputation: 966
Route params should consist of alphabetic characters or _
Please fix your route params name For example:
Route::delete('/org/{org_id}/delete/user/{user_id}', 'App\Http\Controllers\OrganizationController@deleteUserFromOrg')
->name('delete-user-from-org');
And your view blade
<td><a href="{{route('delete-user-from-org', ['org_id'=>$data->id, 'user_id' => $el->id ])}}"><button class="btn btn-danger">Удалить</button></a></td>
Upvotes: 1