Patrick Schocke
Patrick Schocke

Reputation: 1491

laravel relation with only get second relation

I am getting the relation of an relation like this:

Application::select()->where('id', $id)->with('vacancie.company:id,title')->get()

now I am getting the full vacancie model. How can I only get the company id and title, excluding the full vacancie model?

Upvotes: 0

Views: 63

Answers (2)

Marc
Marc

Reputation: 5455

If i remember correctly, should be something like this:

Application::where('id', $id)->with([

    'vacancie' => function($query) {

       $query->select(['id','company_id'])->with([

           'company' => function($query) {
               $query->select(['id','title']);
           }

       ]);

    }
])->get()

Upvotes: 2

Bhoomi Patel
Bhoomi Patel

Reputation: 775

try this query :

$details = Application::where('id', $id)->pluck('id','title');

Upvotes: 0

Related Questions