I have a Category Controller which checks if user is logged in
class CategoryController extends Controller
{
public function __construct() {
$this->middleware('auth');
}
...
My category routes are :
//Category Controller
Route::get('admin/category/{category}/edit', ['uses'=>'categoryController@edit','as'=>'admin.category.edit']);
Route::put('admin/category/{category}', ['uses'=>'categoryController@update','as'=>'admin.category.update']);
Route::get('admin/category/{category}', ['uses'=>'categoryController@show','as'=>'admin.category.show']);
Route::delete('admin/category/{category}', ['uses'=>'categoryController@destroy','as'=>'admin.category.destroy']);
Route::get('admin/category/create', ['uses'=>'categoryController@create','as'=>'admin.category.create']);
Route::get('admin/category', ['uses'=>'categoryController@index','as'=>'admin.category.index']);
Route::post('admin/category', ['uses'=>'categoryController@store','as'=>'admin.category.store']);
Is there a way to give access to these views to only specific user?
For example if user email is admin123@gmail.com then he is allowed to go to those view.
I know I can check like this
if(Auth::user()->email == 'admin123@gmail.com')
{
dd('admin Logged in');
}
But this is possible if i go to individual view and put all my content in the if statement.
Is there way to handle this in controller.
Thanks.