Can you show composer.json
Feb 6, 2022
9
Level 8
Use HasRoles failed
Hi!
Included HasRoles to User model
<?php
namespace App\Models;
use \DateTimeInterface;
use App\Support\HasAdvancedFilter;
use Carbon\Carbon;
use Hash;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasAdvancedFilter;
use SoftDeletes;
use Notifiable;
use HasFactory;
use HasRoles;
public $table = 'users';
protected $hidden = [
'remember_token',
'password',
];
protected $dates = [
'email_verified_at',
'created_at',
'updated_at',
'deleted_at',
];
protected $orderable = [
'id',
'name',
'email',
'email_verified_at',
'country.name',
'golfclub.name',
];
protected $filterable = [
'id',
'name',
'email',
'email_verified_at',
'roles.title',
'country.name',
'golfclub.name',
];
protected $fillable = [
'name',
'email',
'email_verified_at',
'password',
'remember_token',
'country_id',
'golfclub_id',
'created_at',
'updated_at',
'deleted_at',
];
public function getIsAdminAttribute()
{
return $this->roles()->where('title', 'Admin')->exists();
}
public function getEmailVerifiedAtAttribute($value)
{
return $value ? Carbon::createFromFormat('Y-m-d H:i:s', $value)->format(config('project.datetime_format')) : null;
}
public function setEmailVerifiedAtAttribute($value)
{
$this->attributes['email_verified_at'] = $value ? Carbon::createFromFormat(config('project.datetime_format'), $value)->format('Y-m-d H:i:s') : null;
}
public function setPasswordAttribute($input)
{
if ($input) {
$this->attributes['password'] = Hash::needsRehash($input) ? Hash::make($input) : $input;
}
}
public function roles()
{
return $this->belongsToMany(Role::class);
}
public function country()
{
return $this->belongsTo(Country::class);
}
public function golfclub()
{
return $this->belongsTo(Golfclub::class);
}
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
}
But this gives me this error :
Symfony\Component\ErrorHandler\Error\FatalError
Trait 'Spatie\Permission\Traits\HasRoles' not found
Level 102
@birdietorerik the package isn't installed. You need to install it before adding the trait
Please or to participate in this conversation.