3

I'm very new in laravel, I'm following some tutorial

this code work fine

Route::group(['middleware' => 'web'], function() {
    Route::resource('tes', 'TesController');
});
<form action="{{ route('tes.destroy',3) }}" method="post">

until i modified it like this one

Route::resource('tes/keren', 'TesController');

<form action="{{ route('tes/keren.destroy',3) }}" method="post">

It said tes/keren.destroy undefined.... just simple question, which should I modify so, I can route with /

Thank you

3 Answers 3

2

Route::resource('url/resource-route','ResouceControllerName') takes the last segment as a resource name & then automatically build the routes for it.

When you use

Route::resource('tes', 'TesController');

It build the routes for tes resource (like tes.store, tes.create, tes.destroy, etc) But when your change your route to this

Route::resource('tes/keren', 'TesController');

It binds all the routes to keren resource. So use this in your blade file.

<form action="{{ route('keren.destroy', 3) }}" method="post">
Sign up to request clarification or add additional context in comments.

Comments

1

The route helper function takes the route name as the parameter. When you changed the route url, the route name changed to keren.destroy from tes.destroy. So you need to change your form action to

<form action="{{ route('keren.destroy', 3) }}" method="post">

If you ever want to check your route names, just run php artisan route:list from the terminal/console. In this case it should show you something like this.

| GET|HEAD  | tes/keren              | keren.index   | App\Http\Controllers\TesController@index   | web          |
| POST      | tes/keren              | keren.store   | App\Http\Controllers\TesController@store   | web          |
| GET|HEAD  | tes/keren/create       | keren.create  | App\Http\Controllers\TesController@create  | web          |
| GET|HEAD  | tes/keren/{keren}      | keren.show    | App\Http\Controllers\TesController@show    | web          |
| PUT|PATCH | tes/keren/{keren}      | keren.update  | App\Http\Controllers\TesController@update  | web          |
| DELETE    | tes/keren/{keren}      | keren.destroy | App\Http\Controllers\TesController@destroy | web          |
| GET|HEAD  | tes/keren/{keren}/edit | keren.edit    | App\Http\Controllers\TesController@edit    | web          |

Comments

0

route() helper uses route name to build URL, so you should do this instead:

<form action="{{ route('keren.destroy', 3) }}" method="post">

You can see all available routes and route names with this command:

php artisan route:list

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.