I have this method:
public function menuGroups() { return $this->belongsToMany(Layout::class, '_layout_pivot', 'side_menu_item_id', 'side_menu_group_id')->withTimestamps(); }
Result is something like this (one of loop):
"id" => 1 "label" => "system/menu.settings_group" "icon" => "icon-settings" "sort" => 10 "system_employee_id" => 10 "created_at" => "2017-07-19 03:24:06" "updated_at" => "2017-07-17 00:00:00"
I also have table 'system_employees' (just a few sample columns):
+----+----------------+-----------+-----------+-----+---------------------+---------------------+ | id | username | firstname | lastname | age | created_at | updated_at | +----+----------------+-----------+-----------+-----+---------------------+---------------------+ | 1 | Raquel46932071 | Raquel | Heller | 25 | 2017-04-26 05:03:43 | 2017-07-03 21:13:37 | | 2 | Brant13975229 | Brant | Rosenbaum | 30 | 2017-04-25 21:34:46 | 2017-05-07 09:28:27 | +----+----------------+-----------+-----------+-----+---------------------+---------------------+
system_employee_id from >belongsToMany is a foreign key of system_employees and equals system_employees.id
I am trying to combine both, to get system_employee name.
EDIT (as per aynber comment):
I join these two and use paginate(), so I cannot use get and select, or prefix columns:
$this->menuGroups ->leftJoin('system_employees', 'system_employees.id', '=', '_layout_side_menu_groups.system_employee_id') ->paginate($pages, $columns, $pageName, $page);
This is what I am getting:
"id" => 18 "label" => "Some Insert Tester" "icon" => "insico" "sort" => 39 "system_employee_id" => 18 "created_at" => "2017-07-03 00:28:05" "updated_at" => "2017-07-03 00:28:05" "type" => 4 "system_id" => 0 "username" => "System2017" "firstname" => "Rita" "lastname" => "Veygand" "age" => 0 "gender" => "" "email" => "system@gmail.com" "mobile" => "" "rank_id" => 1 "rank_title" => "" "status" => 1 "avatar" => "mysite.com/img/14161939651400nds6k.jpg" "password" => "$2y$10$FIL4LmjLVEZ6SgUsRILqPutTEcaGWcmKyIHwPOBbQfHDYdJM5//2." "remember_token" => "vUI812NTJZ8RWrlX3g3quBy4quVrue1dnOVZEPzifRJdy85cJPQY7RclYNHU"
Question:
How to get 'created_at', 'updated_at' from both tables without using Query Builder? Same applies to any other columns with same names in both tables.
In other words: is there a way to prefix columns in belongsToMany?