Why does your chat have a role?
This makes more sense
Chat::with(['user' => function ($query) {
$query->select('id', 'email', 'first_name', 'last_name')->with('roles');
}])
->orderBy('id', 'DESC')
->paginate(5);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all,
I am using eloquent and spattie v3 for the roles and permissions.
I have a CHAT model with a user_id.
I would like to get the role of each user of a chat:
Chat::with(['user' => function ($query) {
$query->select('id', 'email', 'first_name', 'last_name');
}])
->with('roles')
->orderBy('id', 'DESC')
->paginate(5);
Unfortunately, I am getting the error "Unable to get the requested data!"
Spattie uses these tables:
ROLES:
-id
-name
-guard_name
-created_at
-updated_at
MODEL_HAS_ROLES
-role_id
-model_type
-model_id
What shall I add in the CHAT model to reach a role please?
return $this->hasManyThrough on user model but to which model? As Spattie has not created a model in the model folder of my app.
I am confused.
Thank you.
Why does your chat have a role?
This makes more sense
Chat::with(['user' => function ($query) {
$query->select('id', 'email', 'first_name', 'last_name')->with('roles');
}])
->orderBy('id', 'DESC')
->paginate(5);
Please or to participate in this conversation.