Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Latest commit

 

History

History
67 lines (53 loc) · 2.34 KB

README.md

File metadata and controls

67 lines (53 loc) · 2.34 KB

Fortify Role

Basic Multi Roles authentication package for Fortify.

GitHub license GitHub Workflow Status GitHub release (latest SemVer)

Requirement

  • Laravel ^8.x
  • Laravel/Fortify ^1.x

Installation

I recommended you to install this package only on a fresh project.

Install the package using composer

composer require akunbeben/fortify-role

Usage

Before continuing the process, please make sure the FortifyServiceProvider.php is registered in config/app.php. If it's already registered, you can skip this.

'providers' => [
    ...
    App\Providers\FortifyServiceProvider::class,
],

Then publish the package's vendor files. It's need --force because it will replace the RedirectIfAuthenticated middleware.

php artisan vendor:publish --provider="Akunbeben\FortifyRole\FortifyRoleServiceProvider" --force

And then, add HasRole traits to your User model.

<?php

namespace App\Models;

use Akunbeben\FortifyRole\Traits\HasRole;
...

class User extends Authenticatable
{
    use HasFactory, Notifiable, HasRole;
    ...
}

Now you need to run the migration, I suggest to migrate with the seeder. Or if you want to modify the seeder you can find the seeder file on database/seeders/RoleSeeder.php and database/seeders/UserSeeder.php

php artisan migrate --seed

Finally, you can use the role middleware in your routes like this example below:

...
Route::group(['middleware' => ['auth', 'role:admin']], function () {
    
});

Route::group(['middleware' => ['auth', 'role:user']], function () {
    
});

Notes

  • On the roles table migration file, there is a default value to assign the role to registered user. You can adjust it to your need.