Nothing is returned by the code you shared so it is impossible to understand the error message in context; can you provide all of the relevant code?
App\Models\User::getStoredRole(): Return value must be of type Spatie\Permission\Contracts\Role, App\Models\Company returned
I might be confused or the document doesn't explain well but here is the problem: I had set up Laratrust but it wasn't very good with my current config. Hence, while browsing I saw Spatie had this feature but I had never used it before. I removed all code for Laratrust. Now after setting up everything for Spatie when I am assigning a role I get the this error:
App\Models\User::getStoredRole(): Return value must be of type Spatie\Permission\Contracts\Role, App\Models\Company returned
The error is here:
if ($request->account_type === 'company') {
$company = Company::create([
'user_id' => $user->id,
'company_name' => $request->name,
]);
session(['selected_company' => $company->id]);
$user->assignRole('Super Admin', $company);
}
Inside config.php I set the teams option to true and teams_foreign_key to 'company_id'.
Note that I have only made global roles in seeder which means these roles have company_id as null. This means no specific role for a company exists. I am not willing to make same roles for each company because for my current setup we don't need different roles for each company. All the global roles will be applied/needed. Users have oneToMany realtionship with companies where one user can be a part of a lot of companies and will have different roles in them. Somewhere they can be an admin and somewhere they can be someone else. I have not changed the Company model only User model has this use HasRoles
Please or to participate in this conversation.