laravel nested route with prefix and resource dosent work

laravel route parameters controller
laravel route middleware
laravel route redirect
laravel named routes
laravel get route
route prefix
laravel route::domain
laravel fallback route

I have many routes like these :

Route::resource('/dashboard/class', 'classController');
Route::get('/dashboard/class/get-by-filter', 'classController@getByFilter');
Route::get('/dashboard/class/get-by-search', 'classController@getBySearch');
...
...

Route::resource('/dashboard/orders', 'OrderController');
Route::get('/dashboard/orders/get-by-filter', 'OrderController@getByFilter');
...

now I want to write these with prefix ,group and resources but I have a problem when write like this :

Route::prefix('dashboard')->group(function()
    {

       Route::prefix('class')->group(function()
         {
            Route::resource('/', 'classController');
            Route::get('/get-by-filter', 'classController@getByFilter');
            Route::get('/get-by-search', 'classController@getBySearch');
         });

       Route::prefix('orders')->group(function()
         {
            Route::resource('/', 'OrderController');
            Route::get('/get-by-filter', 'OrderController@getByFilter');
            Route::get('/get-by-search', 'OrderController@getBySearch');
         });

});

why return 404 when I try to access show address like this :

example.com/dashboard/orders/4

I'm using group routing like this.

<?php
Route::group(['prefix' => 'dashboard'], function() {

    Route::group(['prefix' => 'class'], function() {
        Route::resource('/', 'classController');
        Route::get('/get-by-filter', 'classController@getByFilter');
        Route::get('/get-by-search', 'classController@getBySearch');
    });

    Route::group(['prefix' => 'orders'], function() {
        Route::resource('/', 'OrderController');
        Route::get('/get-by-filter', 'OrderController@getByFilter');
        Route::get('/get-by-search', 'OrderController@getBySearch');
    });
});

Try this. May be this will help you.

Use of nested route groups with 'prefix' and 'as' parameters results in , I want to write these with prefix ,group and resources but I have a problem when write like this : Route::prefix('dashboard')->group(function()  Nested Resource Controllers and Routes: Laravel CRUD Example. When building CRUD-like projects, sometimes you want some items be accessible only with their parent, for example in countries-cities relationships, you don’t want to list all the cities in the world, but only by country, like /countries/123/cities, where 123 is country_id.

You need to write resource instead of get

Route::prefix('dashboard')->group(function()
    {

       Route::prefix('class')->group(function()
         {
            Route::resource('/', 'classController');
            Route::get('/get-by-filter', 'classController@getByFilter');
            Route::get('/get-by-search', 'classController@getBySearch');
         });

       Route::prefix('orders')->group(function()
         {
            Route::resource('/', 'OrderController');
            Route::get('/get-by-filter', 'OrderController@getByFilter');
            Route::get('/get-by-search', 'OrderController@getBySearch');
         });

});

Routing - Laravel, When you nest Route groups using the properties 'prefix' and 'as', both the 'prefix' AND 'as' GitHub is home to over 50 million developers working together to host and review code, manage projects Example is below, tested in Laravel v 5.2.41​. Resource controllers do not respect group name #14833. I'm using route groups to try and stop duplication within my Routes file. I have one main group, frontend. This has the namespace Frontend and as frontend. Nested within that group, is another group. This group has the prefix account which appends /account/ to each route. It also has as account.. The routes inside the nested group, I'd expect

Okay i think i got it, all you need to pass {id} in the url then dd($id) in your controller method.

Route::group(['prefix'=>'dashboard'], function()
{
    Route::group(['prefix'=>'class'], function()
    {
        Route::resource('/', 'classController');
        Route::get('/get-by-filter', 'classController@getByFilter');
        Route::get('/get-by-search', 'classController@getBySearch');
    });
    Route::group(['prefix'=>'orders'], function()
    {
        Route::resource('/{id}','classController');
        Route::get('/get-by-filter', 'OrderController@getByFilter');
        Route::get('/get-by-search', 'OrderController@getBySearch');
    });
});

I suggest you to use proper namespace and make sure your classController redirect to exact method.

Group nesting in routes, Routes defined in the routes/api.php file are nested within a route group by the RouteServiceProvider . Within this group, the /api URI prefix is automatically applied so you do not need to Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) { // });. Route Cross-Origin Resource Sharing (​CORS). Group nesting in routes I know laravel 5 do not support nested groups, and it's easy to achieve 2 lvls url like: it doesn't work at all. Any advise on this?

Route groups inside a resource, I know laravel 5 do not support nested groups, and it's easy to achieve 2 lvls url like: function() { Route::resource('commissions.committee-members', I will get​: // mydomain.com/admin // My routes Route::group(['prefix'  The most concise screencasts for the working developer, updated daily. There's no shortage of content at Laracasts. In fact, you could watch nonstop for days upon days, and still not see everything!

Nested Resource Controllers and Routes: Laravel CRUD Example , right now i'm doing something like this in my routes file, which feels too hacky for me: http://laravel.com/docs/5.1/controllers#restful-nested-resources With nested resource you can prefix the first resource but not the second : Visibility: you can see all your routes without running php artisan route:list . Routes defined in the routes/api.php file are nested within a route group by the RouteServiceProvider. Within this group, the /api URI prefix is automatically applied so you do not need to manually apply it to every route in the file. You may modify the prefix and other route group options by modifying your RouteServiceProvider class.

Simple and Easy Laravel Routing ― Scotch.io, This article will show you how to do it, using Route::resource() and usual There won't be any specific /cities URL, only the one that contains Country. Now, let's meet NESTED RESOURCE CONTROLLERS – here's the syntax that That means that all URLs should contain /countries/[country_id]/ prefix. Nope, nested groups aren't supported. The second route would be available at /users because it overwrites the group attributes set by the first group. Lumen doesn't keep track of a group stack like Laravel.

Comments
  • thank you for your response. I try this way but it dose not work yet!
  • and also run this command on console php artisan route:list then this will show you all the routes listing.
  • when I run this: php artisan route:list , I can see there is a route like this : /dashboard/orders/{}. but when I type in url get 404 err.
  • Firstly clear your laravel.log file and run again hit orders url and then check laravel.log file. error will be logged there.
  • I'm sorry, that was my wrong in type. I do this but It dose not work yet!