Aronaman
1 month ago
139
2
Laravel

array

Posted 1 month ago by Aronaman

relationship booking.php //model

public function individualRooms()

    {
      return $this->belongsToMany(individualRoom::class,'booking__individualroom');
    }
 App\Booking::with('individualRooms')->get()

what i want is all the individual roooms and itry this

})->with('individualRooms')->get()->pluck('individualRooms','id')->toArray();

output

array:3 [▼
  2 => array:1 [▼
    0 => array:8 [▼
      "id" => 3
      "room_id" => 1
      "room_no" => 202
      "room_floor" => null
      "created_at" => "2020-01-26 16:02:39"
      "updated_at" => "2020-01-26 16:02:39"
      "deleted_at" => null
      "pivot" => array:2 [▶]
    ]
  ]
  3 => array:2 [▼
    0 => array:8 [▶]
    1 => array:8 [▶]
  ]
  4 => array:2 [▼
    0 => array:8 [▶]
    1 => array:8 [▶]
  ]
]

but what i need is

0 => array:8 [▼
    "id" => 8
    "room_id" => 1
    "room_no" => 401
    "room_floor" => null
    "created_at" => "2020-02-03 19:31:44"
    "updated_at" => "2020-02-03 19:31:44"
    "deleted_at" => null
    "pivot" => array:2 [▶]
  ]
  1 => array:8 [▼
    "id" => 3
    "room_id" => 1
    "room_no" => 202
    "room_floor" => null
    "created_at" => "2020-01-26 16:02:39"
    "updated_at" => "2020-01-26 16:02:39"
    "deleted_at" => null
    "pivot" => array:2 [▶]
  ]
2 => array:8 [▼
    "id" => 3
    "room_id" => 1
    "room_no" => 202
    "room_floor" => null
    "created_at" => "2020-01-26 16:02:39"
    "updated_at" => "2020-01-26 16:02:39"
    "deleted_at" => null
    "pivot" => array:2 [▶]
  ]

any help, please??

Please sign in or create an account to participate in this conversation.