i have three table as follows:
users:
id, fullname, phone ...
tasks:
id, user_id, title, description ...
tasks_state:
id, task_id, comment, rating, createa_at, updated_at
i am trying to use Relationships in laravel for order by updated_at
in table tasks_state
Model tasks
public function taskstate()
{
return $this->hasOne(TaskState::class, 'task_id');
}
Model tasks_state
public function task()
{
return $this->belongsTo(Tasks::class, 'id', 'taks_id');
}
I want the data returned sorted by field updated_at
in table tasks_state
when i use:
Tasks:with('taskstate')->get();
Look forward to your help :(