Answers for "how to group route in laravel"

PHP
6

laravel Route::group definition

Route::group(['prefix'=>'accounts','as'=>'account.'], function(){
    Route::get('/', 'AccountController@index')->name('index');
    Route::get('connect', 'AccountController@connect')->name('connect');
});

Route::group(['prefix'=>'quotes','as'=>'quote.'], function(){
    Route::get('/', 'QuoteController@index')->name('index');
    Route::get('connect', 'QuoteController@create')->name('create');
});
Posted by: Guest on July-27-2020
1

Laravel Route Group

Route::group(['prefix' => 'post', 'middleware' => ['auth']], function(){
        Route::get('all','Controller@post');
        Route::get('user','Controller@post');
    })
Posted by: Guest on July-18-2021
2

laravel route namespace and prefix

Route::prefix('admin')->group(function () {
    Route::get('/users', function () {
        // Matches The "/admin/users" URL
    });
});
Posted by: Guest on December-15-2020
-1

route group in laravel

Route::group(['prefix' => 'admin']){
	Route::get('/',function(){
    	//...
    });
}
Posted by: Guest on January-30-2021
0

laravel route group

Route Groups is an essential feature in Laravel, which allows you to group all the routes. Routes Groups are beneficial when you want to apply the attributes to all the route
  Here, we have used the group() function, which takes two parameters, as mentioned in the syntax.

  1-	array of attributes, string,Closure
  2-	callback function, string $routes
  	
	The first parameter is an associative array containing namespace, prefix, or middleware for the group of routes
	The second paramter is a callback function which contain the list of routes inside the group.
Syntax:
	Route::group( [ ] , callback); //syntax parameters (\Closure|string|array $attributes, \Closure|string $routes)
	Route::group( [ ] , function(){});

Group Without Naming:

	Route::group([],function () {
      Route::get('/', function () { });
	});

Naming/Prefixing Group:

	Route::group(['prefix'=>"name"],function () {
      Route::get('/', function () { });
	});
	
    Route::group(['prefix'=>'users','as'=>'user.'], function(){
        Route::get('/', [cotrollerName::class,"methodName"]);
    });

Group with Middleware:

	Route::group(['middleware' => 'auth'], function() {
       	Route::get('/dashboard', [cotrollerName::class,"methodName"]); 
      	Route::resource('users', 'UserController');
    });

Group with Namespace, Prefix, Middleware:

	Route::group(['namespace' => 'Admin', 
            'prefix' => 'admin',
            'middleware' => 'auth'], function() {
        Route::resource('users', 'UserController');
    });
Posted by: Guest on October-28-2021
0

route parameter type laravel

Route::get('/user/{name}', function ($name) {
    //
})->where('name', '[A-Za-z]+');

Route::get('/user/{id}', function ($id) {
    //
})->where('id', '[0-9]+');

Route::get('/user/{id}/{name}', function ($id, $name) {
    //
})->where(['id' => '[0-9]+', 'name' => '[a-z]+']);

reference : https://laravel.com/docs/8.x/routing#parameters-regular-expression-constraints
Posted by: Guest on December-13-2020

Browse Popular Code Answers by Language