S
S
Sergey Sergeev2015-02-16 12:53:48
Laravel
Sergey Sergeev, 2015-02-16 12:53:48

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

2 answer(s)
T
TekVanDo, 2015-02-16
@alokazay

Set links

class User extends Eloquent {

    public function task()
    {
        return $this->hasOne('Task');
    }

}

class Task extends Eloquent {

    public function user()
    {
        return $this->belongsTo('User');
    }

}

Well, the sample should be in the spirit of more details here
Task::with('user')->where('user_id', '=', $id)->get()

M
Maxim, 2015-02-16
@maxloyko

I think here you will find the answer Eloquent ORM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question