I don't know if it is actually posible but it might look like this:
Schema:
User
id, name, last_name, etc.
Condition
id, name
User_Condition
id, user_id, condition_id, active, start_date, end_date
I want to be able to do something similar to this: $user->conditions->active()
or $user->conditions->active
where it returns any row/relations in which active = 1
You want to get all the active conditions of a user, right?
If so, you get them by following query.
echo $user->conditions()->where('user_condition.active', true)->get();
Make sure you make a belongsToMany
relationship in user model
public function conditions()
{
return $this->belongsToMany('App\Condition', 'user_condition');
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments