Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- {
- "id": 140,
- "name_first": "hasan",
- "name_last": "hasibul",
- "profile_image": "/assets/images/default-profile-img.png",
- "created_at": "2013-09-18 08:19:50",
- "last_login": "2013-12-26 11:28:44",
- "status": "active",
- "last_update": "2013-10-15 13:40:47",
- "google_refresh_token": null,
- "is_admin": 1,
- "updated_at": null,
- "pivot": {
- "trip_id": 200,
- "user_id": 140
- }
- }
- public function trips(){
- return $this->belongsToMany('Trip');
- }
- public function users(){
- return $this->belongsToMany('User');
- }
- public function index($tripId)
- {
- $userCollection = Trip::find($tripId)->users;
- return $userCollection;
- }
- //get all the users belongs to the trip
- Route::get('trips/{tripId}/users', array(
- 'as' => 'trips/users/index',
- 'uses' => 'TripUserController@index'
- ));
- public function toArray()
- {
- $attributes = $this->attributesToArray();
- $attributes = array_merge($attributes, $this->relationsToArray());
- unset($attributes['pivot']['user_id']);
- return $attributes;
- }
- protected $hidden = [
- 'pivot'
- ];
Add Comment
Please, Sign In to add comment