
ERROR
BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.
BadMethodCallException Method Illuminate\Database\Eloquent\Collection::permissions does not exist.
The hint here is ‘Collection‘…
If somehow you got this error while you have check all code is ok, relationship is ok, then try to check either you use first() or get() method.
Supposedly you use first() instead of get() method as get() method will return a collection() while first() just return a record.
Tinker
$r = App\Models\Role::where('slug','super-admin')->first()
= App\Models\Role {#7268
id: 1,
name: "Super Admin",
slug: "super-admin",
created_at: "2023-07-27 01:11:24",
updated_at: "2023-07-27 01:11:24",
}
$u = App\Models\User::where('name','Ghazali Tajuddin')->first()
= App\Models\User {#7278
id: 1,
name: "Ghazali Tajuddin",
email: "ghazali.tajuddin@gmail.com",
email_verified_at: "2023-07-27 01:11:24",
#password: "",
#remember_token: null,
created_at: "2023-07-27 01:11:24",
updated_at: null,
}


If you just like me, accidently renaming the migration and then later realise something goes wrong or having some kind of migration error that really makes you want to jump out shouting hardly, this is might be a solution for you.

