Support the ongoing development of Laravel.io →
Eloquent
Last updated 1 year ago.
0

http://laravel.com/docs/5.1/eloquent-relationships Define relationships in your models, e.g.

// App/Call
...
    function place() {
        return $this->belongsTo('App\Place');
    }

You should be able to end up with:

$calls = \App\Call::with([
     'places' => function ($query) { $query->select('id', 'name'); },
     'departments' => function ($query) { $query->select('id', 'name'); },
     'callStatuses' => function ($query) { $query->select('id', 'name'); },
     ...
])->get(['title', ...]);

$calls[0]->place->name;
$calls[0]->callStatus->name;
0

tanerkucukyuruk said:

http://laravel.com/docs/5.1/eloquent-relationships Define relationships in your models, e.g.

// App/Call
...
   function place() {
       return $this->belongsTo('App\Place');
   }

You should be able to end up with:

$calls = \App\Call::with([
    'places' => function ($query) { $query->select('id', 'name'); },
    'departments' => function ($query) { $query->select('id', 'name'); },
    'callStatuses' => function ($query) { $query->select('id', 'name'); },
    ...
])->get(['title', ...]);

$calls[0]->place->name;
$calls[0]->callStatus->name;

calls is related to places, and places is related to departaments.

with the work in this case?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.