加入后,我得到了带有2个ID列的表。现在我不知道如何在Controller和Blade中同时访问这两个ID。
在Blade中,当我尝试{{$value->id}}
时,它将获得第二个ID。
$users = User::where('user_id', $user_id)
->join('tagged', 'tagged.taggable_id', '=', 'users.id')
->orderBy('users.id', 'asc')
->get();
给我:
-------------------------------------------------------
| id | name| phone | id | taggable_type | taggable_id |
-------------------------------------------------------
如何在Controller和Blade中同时获得ID?
答案 0 :(得分:0)
$users = DB::table('users')->where('user_id','=', $user_id)
->select('users.*','tagged.id as tagged_id') //add fields required from tagged table in this row
->join('tagged', 'tagged.taggable_id', '=', 'users.id')
->orderBy('users.id', 'asc')
->get();
Use $users->tagged_id and $users->id in view