I"m try to role permission system by laravel 5.6
when i try to register with default auth(php artisan make:auth) i get this error
"Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Trait 'App\HasRoles' not found"
this my model user.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
use HasRoles;
protected $guard_name = 'web';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
By adding their HasRoles Trait to our classes, we can then use the Trait's functionality to manage roles. Additionally, the Laravel framework itself uses Traits to layer functionality and complexity when needed. Notable examples that you might run across include AuthenticatesUsers and Notifiable.
Exception is an event that occur during the execution of program and disrupt the normal flow of instructions. In Laravel, there are handler class through which you can handle all the exception in your application. report () method is used to log exceptions and render () method is used to convert exception in HTTP response.
Let us evoke our first step to get started. Generically, i invoke my first step by installing the new laravel application. However, if you have done this task already, then you can skip it and directly move to the second step. Run the command to start the project installation. Right after the project installation, get inside the project directory.
Run the command to start the project installation. Right after the project installation, get inside the project directory. Please insert the following code in .env file, and it evokes the connection between laravel and database with refined consensus.
Try this. Import HasRoles package as follow;
use Spatie\Permission\Traits\HasRoles;
I'm guessing you're using the Spatie Laravel Permission package.
If so, you need to import the class like so:
use Spatie\Permission\Traits\HasRoles;
Run this command
composer install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With