Trait "Spatie\Permission\Traits\HasRoles" not found when using in custom package
coreyfreeman82 opened this issue · 0 comments
coreyfreeman82 commented
I want my own package to rely on this package so I added it to my package composer.json and use the HasRoles trait in my own trait. When I try to visit my application it gives me the trait not found error.
Versions
- spatie/laravel-permission package version: dev-main 2cc5362
PHP version: 8.2.8
Database version: libmysql - mysqlnd 8.2.8
To Reproduce
Steps to reproduce the behavior:
- Require spatie/laravel-permission in custom package
- Create a trait
- Use hasRoles in the the trait
- Use custom trait in application user model
Here is my example code and/or tests showing the problem in my app:
<?php
namespace Author\Package\app\Traits;
use Spatie\Permission\Traits\HasRoles;
use Author\Package\app\Models\MenuItem;
trait HasMenuItems
{
use HasRoles;
public function getMenuItems()
{
if($this->roles()->exists()) {
return MenuItem::where('role_id', $this->roles()->first()->id)->orderBy('position')->get();
}
return collect();
}
}
In my package composer.json under require: "spatie/laravel-permission": "^6.0@dev"