Route::group(['middleware'=>'auth'], function() { code example
Example 1: Route::group(['middleware'=>'auth'], function() {
Route::group(['middleware' => ['auth']], function () {
Route::get('home', 'HomeController@index');
Route::post('save-user', 'UserController@saveUser');
Route::put('edit-user', 'UserController@editUser');
});
Example 2: how to attach the middleware to a route definition
Route::get('profile', function () {
// Only verified users may enter...
})->middleware('verified');
Example 3: Route::group(['middleware'=>'auth'], function() {
protected function mapAuthRoutes()
{
Route::middleware('web')
->namespace('App\Http\Controllers\Auth')
->group(base_path('routes/auth.php'));
}
Example 4: Route::group(['middleware'=>'auth'], function() {
Route::middleware(['first', 'second'])->group(function () {
Route::get('/', function () {
// Uses first & second Middleware
});
Route::get('user/profile', function () {
// Uses first & second Middleware
});
});