I am using Lumen Laravel 5.1. I have a many to many relation between task and user, and pivot table called task_user
, I recently asked this question, inspired by the answer and by reading the documentation, I think I can do this
$users = User::tasks()
->where('domain_id', $domainId)
->where('created_by', $userId)
->orWhere(User::tasks()->find($userId))
->Where(function ($query) {
$query->where("is_done", 0)
->orderBy('due_date', 'DESC');
})
->Where(function ($query) {
$query->Where("is_done", 1)
->Where("closed_dated", Carbon::today())
->orderBy('closed_date', 'ASC');
})
->get();
Before I accept his answer I have two questions:
1- A user can have his id related to a task, in 2 places
task_user
table if is an assigneecreated_by
in tasks table, if he created it
So I want to know if he's an assignee or if he created it, both cases I want to display his tasks. Found nothing on google, so can I do this?
where(....) -> orwhere(model::find())
- My second question is: Should I use
->pivot->id
to get to task, instead of find()? The docs about->pivot
are confusing and the tutorials I read don't use it. I don't know if it helps me.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire