Answer the question
In order to leave comments, you need to log in
How to make a related selection from 2 tables in laravel?
Hey!
I have two tables for example
User -> id, name
Task -> user_id, task.
How can I get all tasks only instead of user_id so that name is substituted?
Answer the question
In order to leave comments, you need to log in
Set links
class User extends Eloquent {
public function task()
{
return $this->hasOne('Task');
}
}
class Task extends Eloquent {
public function user()
{
return $this->belongsTo('User');
}
}
Task::with('user')->where('user_id', '=', $id)->get()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question