Looks good if you are not going to add a lot more routes, if you ask me.
Aug 3, 2016
5
Level 2
Using middleware as role
I'm newbie in Laravel. I'm developing School Management System in Laravel.I made user role as follows
Is that okey ? using custom middlware for role ? Is there any better approuch ?
Route::group(['middleware' => ['web']], function()
{
Route::auth();
/*
*******************************
* Routes for education system
*******************************
*/
// Route for only Sysadmins
Route::get('edu/user/sysadmin', function()
{
return view('edu.user.sysadmin');
})->middleware('isSystemAdmin');
/*********************
* Route for Admin
**********************/
Route::group(['middleware' => ['isAdmin']], function()
{
Route::get('edu/user/admin', function()
{
return view('edu.user.admin');
});
/************************
* Route for Students
*************************/
Route::get('edu/user/admin/students', 'AdminController@students');
/***************************
* Route for School Setup
****************************/
Route::get('edu/user/admin/calendar', 'AdminController@calendar');
// Grade level
Route::get('edu/user/admin/grade_level', 'AdminController@grade_level');
// Announcement
Route::get('edu/user/admin/announcement', 'AdminController@announcement');
});
// Routes for only Teachers
Route::get('edu/user/teacher', function()
{
return view('edu.user.teacher');
})->middleware('isTeacher');
// Routes for only Parents
Route::get('edu/user/parent', function()
{
return view('edu.user.parent');
})->middleware('isParent');
// Routes for only Students
Route::get('edu/user/student', function()
{
return view('edu.user.student');
})->middleware('isStudent');
});
Thanks in advance!
Level 80
@orgil It’s fine to use middleware to restrict access to resources, but as @ricardovigatti says you might want to group these routes:
Route::auth();
Route::group(['middleware' => ['auth', 'admin']], function () {
// Admin-only routes
});
Route::group(['middleware' => ['auth', 'teacher']], function () {
// Teacher-only routes
});
Route::group(['middleware' => ['auth', 'student']], function () {
// Student-only routes
});
Please or to participate in this conversation.