Guest User

Untitled

a guest
Oct 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. [
  2. {
  3. "id": 140,
  4. "name_first": "hasan",
  5. "name_last": "hasibul",
  6. "profile_image": "/assets/images/default-profile-img.png",
  7. "created_at": "2013-09-18 08:19:50",
  8. "last_login": "2013-12-26 11:28:44",
  9. "status": "active",
  10. "last_update": "2013-10-15 13:40:47",
  11. "google_refresh_token": null,
  12. "is_admin": 1,
  13. "updated_at": null,
  14. "pivot": {
  15. "trip_id": 200,
  16. "user_id": 140
  17. }
  18. }
  19.  
  20. public function trips(){
  21. return $this->belongsToMany('Trip');
  22. }
  23.  
  24. public function users(){
  25. return $this->belongsToMany('User');
  26. }
  27.  
  28. public function index($tripId)
  29. {
  30. $userCollection = Trip::find($tripId)->users;
  31. return $userCollection;
  32. }
  33.  
  34. //get all the users belongs to the trip
  35. Route::get('trips/{tripId}/users', array(
  36. 'as' => 'trips/users/index',
  37. 'uses' => 'TripUserController@index'
  38. ));
  39.  
  40. public function toArray()
  41. {
  42. $attributes = $this->attributesToArray();
  43. $attributes = array_merge($attributes, $this->relationsToArray());
  44. unset($attributes['pivot']['user_id']);
  45. return $attributes;
  46. }
  47.  
  48. protected $hidden = [
  49. 'pivot'
  50. ];
Add Comment
Please, Sign In to add comment