-
Drag all folders inside the
LaravelRanks
folder into the root of your Laravel project -
Change the ranks that you want to have in
database\seeders\RankSeeder.php
2.1 (Optional) Customize ranks by adding an array and changingRankName
andRankValue
to what you want.[ 'rankName' => 'RankName', 'rankValue' => RankValue, ],
-
In
app\Http\Kernel.php
add'rank' => \App\Http\Middleware\RankChecker::class,
at the bottom of$routeMiddleware
. -
Add
'rank',
to$fillable
inuser.php
. -
Add the following to
user.php
public function rank() { return $this->hasOne(UserRanks::class); } -
Add
$rank = !User::count() ? 999 : 1;
inRegistrationController.php
after you validate the filled in form details. -
Add
'rank' => $rank
to yourUser::create
for example: User::create([ 'name' => $request->name, 'username' => $request->username, 'email' => $request->email, 'password' => Hash::make($request->password), 'rank' => $rank ])->sendEmailVerificationNotification(); -
Run
php artisan migrate
. -
Run
php artisan db:seed -class=RankSeeder
You can authorize a rank to access a route by adding them to the middleware()
like this:
public function __construct() {
$this->middleware(['rank:Admin']);
}
Or if you want multiple ranks to be able to access a route:
public function __construct() {
$this->middleware(['rank:Admin,Moderator']);
}