I am new to laravel. Maybe the question is not consistent with this problem. The problem is that. I have one database table for many, like a hotel and a room. One hotel can have several rooms. My goal:
public function edit($id) {
echo $id;
$data['hotel'] = Hotel::find($id);
$data['rooms'] = Room::where("hotelId", $id)->get();
return view('include.middle')->nest('main', 'hotel.edithotel', $data);
}
I get data from a table of rooms and hotels. Sure, there may be several rooms.
In sight. I want to get all the editing data for the hotel and room.
editHotel.blade.php
{{ Form::model($hotel, array('route' => array('hotel.update', $hotel->hotelId), 'method' => 'PUT')) }}
{{ Form::model($rooms, array('route' => array('room.update', $rooms->roomId), 'method' => 'PUT')) }}
But I get an error like
Undefined property: Illuminate\Database\Eloquent\Collection::$roomId (View: /Users/apple/hotelbooking/resources/views/hotel/edithotel.blade.php)
I set the primary keys in Room and Hotel Model.
Database schema.
Hotel
hotelId | name | address
1 | example hotel somewhere
Room
roomId | hotelId | name | price
1 1 Delux $300
2 1 Economy $100
source
share