1

if i use as to name a column NULL is returned. I want to name the column like (id_company as idC).

This is the code in question:

$entity = Entity::with(['typeEntity' => function ($q) {
    $q->select(['id_type_entity as ite', 'name_type_entity'])->get();
}, 'company' => function ($q) {
    $q->select(['id_company', 'name_company'])->get();
}])->get();

Without this, it works as expected.

C_B
  • 2,620
  • 3
  • 23
  • 45

1 Answers1

0

The easiest way would be to use the get() method and assign the alias you want to use here.

An example from a similar question:

Products::where("actice", "=", true)
    ->joinWithTags
    ->get(['tags.name AS tag_name', 'products.*'])
    ->toArray();
Community
  • 1
  • 1
C_B
  • 2,620
  • 3
  • 23
  • 45