📕
Sprnva Docs
  • Introduction
  • What's New?
  • Installation
    • Requirements
    • Download Sprnva zip no composer required
    • Install Sprnva Using Composer
    • Setup Config
  • Deployment
  • File Structure
  • Database
    • Select
    • SelectLoop
    • Insert
    • Update
    • Delete
    • Query
    • Seeder
    • Paginate
    • With
    • andFilter
    • withCount
    • get
  • Query Builder
  • Migration
    • INSTANCES
      • NEW
      • RENAMETABLE
      • DROP
      • CHANGE
    • DUMPS
      • dump
      • dump prune
    • MAKE
    • MIGRATE
      • migrate
      • migrate fresh
    • ROLLBACK
  • Routing
    • with parameter
    • multiple parameters
    • with closure
    • group
    • controller grouping
  • Controllers
    • methods
  • Views
    • Passing Parameters
  • Validation
    • validate
      • validation type
  • Authentication
  • Alert Messages
  • Default Helpers
  • CSRF Protection
  • Email
  • Packages
    • Fortify
  • Themes and Templates
Powered by GitBook
On this page
  1. Routing

group

We sometimes need to group our routes to save extra coding more prefixes and one-by-one tagging out middleware auth. Route groupings is here to save you.

Route::group($param, $action);

$param : is an array that contains the prefix and the middleware of the group.

$action : is a function where we declare the routes inside.

For example, let's take a look with route grouping in our profile route.

Route::group(['prefix' => 'profile', 'middleware' => ['auth']], function () {
    Route::get("/", ['ProfileController@index']);
    Route::post('/', ['ProfileController@update']);
    Route::post('/changepass', ['ProfileController@changePass']);
    Route::post('/delete', ['ProfileController@delete']);
});

grouping is just like saying: (/profile, /profile/changepass, /profile/delete).

First we need to define a prefix to our group by saying ['prefix' => 'your-desired-prefix'] and we define the middleware saying ['middleware' => ['auth']]. Basically when saying ['middleware' => ['auth']] all the routes the we define inside the group will be protected by auth. If you are not authenticated you cannot access this defined routes.

Previouswith closureNextcontroller grouping

Last updated 2 years ago