I'm going crazy, I'm trrying to use the Spatie Permission library, however, when I do this:
collect(Roles::all())->each(function ($role) {
Role::create(['name' => $role, 'team_id' => 1]);
});
dump(role::findByName('administrator')); // results in: There is no role named `administrator`.
And yes, the roles table does have the administrator role, and the guard (sanctum) does match as well.
Took the wrong result, this is the actual query: "select * from "roles" where ("team_id" is null or "team_id" = ?) and "name" = ? and "guard_name" = ?"
This is the Spatie function:
protected static function findByParam(array $params = [])
{
$query = static::query();
if (PermissionRegistrar::$teams) {
$query->where(function ($q) use ($params) {
$q->whereNull(PermissionRegistrar::$teamsKey)
->orWhere(PermissionRegistrar::$teamsKey, $params[PermissionRegistrar::$teamsKey] ?? getPermissionsTeamId());
});
unset($params[PermissionRegistrar::$teamsKey]);
}
foreach ($params as $key => $value) {
$query->where($key, $value);
}
return $query->first();
}
The $params variable does actually contain the correct "namen" and "guard_name" (no "team_id")...