lumen/laravel pluck not working in with relationship

  builder, laravel, lumen, php, relationship

I have pivot table vacancy_tag. I tried different options (value,select, lists and etc), but didn’t go further than that. My request:

Vacancy::where('id',1)->with(['tags' => function ($q){
            $q->select('tags.id')->pluck('id');
        }])->get()->toArray();

return this:

...
"tags" => array:2 [▼
      0 => array:1 [▼
        "id" => 1
      ]
      1 => array:1 [▼
        "id" => 2
      ]
...

but need this:

"tags" => [
       1,
       2
]

I would like to receive the data result in a query, without using a methods transformation of the collection, if possible.

Source: Ask PHP

LEAVE A COMMENT