Baspa
Baspa

Reputation: 1168

Route to grouped routes with prefix correctly in Laravel

I have a group of routes with a prefix.

In my web routes the routes with an admin prefix go to a separate route file:

Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'admin.', 'middleware' => 'admin'], function () {
    includeRouteFiles(__DIR__ . '/Admin/');
});

So I have to add admin as prefix in my routes. In my Admin directory I defined the routes as following:

Route::prefix('organization/{organization}')->group(function () {
    Route::post('seed', 'SeedController@store')->name('seed');
});

My problem is routing to the routes inside this group. I used the command php artisan route:list to see more info about my routes. It says:

When I link to this route as admin.seed in my form I get the following error:

Missing required parameters for [Route: admin.seed] [URI: admin/organization/{organization}/seed]. (View: D:\xampp\htdocs\minute-mn-503\resources\views\admin\organizations\show.blade.php)

I tried linking it as:

But none of them seems to work. This is the line of code for example:

<form method="POST" action="{{ route('admin/organization/'.$organization->id.'.seed') }}">

Any idea on how I might route these correctly? I couldn't find any clear explanation in the Laravel docs.

Upvotes: 0

Views: 1641

Answers (1)

Davit Zeynalyan
Davit Zeynalyan

Reputation: 8618

You must be using this:

<form method="POST" action="{{ url('admin/organization/' . $organization->id .'/seed') }}">

or:

<form method="POST" action="{{ route('admin.seed', $organization->id) }}">

Upvotes: 1

Related Questions