Reputation: 2735
I have faced some problem when i am going to use middleware
group of Laravel 5.2 framework.
My routes.php file is:
Route::group(['prefix' => 'categories'], function () {
Route::get('all', ['as' => 'allCategory' , 'uses' => 'CategoryController@index']);
Route::get('add', ['as' => 'addCategory', 'uses' => 'CategoryController@create']);
Route::get('edit/{id}', ['as' => 'editCategory', 'uses' => 'CategoryController@edit']);
Route::post('save', ['as' => 'saveCategory', 'uses' => 'CategoryController@store']);
Route::put('update', ['as' => 'updateCategory', 'uses' => 'CategoryController@update']);
Route::get('delete/{id}', ['as' => 'deleteCategory', 'uses' => 'CategoryController@destroy']);
});
Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
return view('welcome');
});
Route::auth();
Route::get('/home', 'HomeController@index');
});
I am using here laravel defaults login/registration authentication.Using php artisan make:auth
command.I want to give user restricted for some routes
such as categories
route group.So,
'web'
and 'auth'
middleware
?Thanks.
N.B : If you need to know about any files then just comment me below i will add those files.
Upvotes: 0
Views: 3078
Reputation: 1580
This is a feature of laravel 5.2. 2 default middleware is web and api.
You need place category group route inside web middleware.
Web middleware make your request contains cookies, session, csrf_token used for authentication. Otherwise, api middleware used for application that simple query get or post without request header, assume mobile app.
Auth middleware based on web middleware.
Upvotes: 4