SQL qvery return id 1 on all rows
$bookings = Booking::with('client')
->join('room_types', 'room_types.id', '=',
'bookings.room_type_id')
->join('language_room_type', 'language_room_type.room_type_id',
'bookings.room_type_id')
->join('languages', 'languages.id', '=', 'language_room_type.language_id')
->where('languages.name', $lang)
->orderByDesc('bookings.end_date')
->paginate(10);
on
@foreach ($bookings as $booking)
{{ $booking->id}}
@endforeach
returns 1 on all rows
Try adding a select
$bookings = Booking::with('client')
->select('bookings.*')
->join('room_types', 'room_types.id', '=',
'bookings.room_type_id')
->join('language_room_type', 'language_room_type.room_type_id',
'bookings.room_type_id')
->join('languages', 'languages.id', '=', 'language_room_type.language_id')
->where('languages.name', $lang)
->orderByDesc('bookings.end_date')
->paginate(10);
dd($booking->pluck('id'));
This also returns all 1?
$bookings = Booking::with('client')
->paginate(10);
no it returns diferent data as it need to do
with select show proper id but no data form room_types joins
Add ->select('bookings.*', 'room_types.*')
still no data form room_types
What do you get if you dd?
dd($bookings->toArray());
array:12 [▼
"current_page" => 1
"data" => array:2 [▼
0 => array:33 [▼
"id" => 1
"client_id" => 2
"room_type_id" => 1
"start_date" => "1993-10-07"
"end_date" => "2018-01-12"
"status" => 1
"total" => 168055093
"created_at" => null
"updated_at" => null
"price_id" => 4
"quantity" => 3
"wifi" => 1
"wardrobe" => 1
"tv" => 1
"table" => 1
"sofa" => 0
"refrigerator" => 1
"phone" => 1
"desk" => 1
"kitchen" => 1
"hairdryer" => 1
"beds" => 1
"kettle" => 1
"bathroom" => 1
"balcony" => 1
"air_conditioning" => 1
"lang" => "mk"
"discount_id" => 1
"language_id" => 1
"title" => "ПРЕМИЕР АПАРТМАНИ"
"description" => """
<p>Сонувајте додека се сместувате во нашиот апартман од 42м² опремен со кралски кревет (queen bed), простор за седење и Чајна кујна – мала кујничка. ▶
<br />
Големина на апартманот: 42м²</p>
"""
"name" => "mk"
"client" => array:12 [▶]
]
1 => array:33 [▼
"id" => 1
"client_id" => 10
"room_type_id" => 1
"start_date" => "2016-01-04"
"end_date" => "2017-06-17"
"status" => 1
"total" => 5
"created_at" => null
"updated_at" => null
"price_id" => 4
"quantity" => 3
"wifi" => 1
"wardrobe" => 1
"tv" => 1
"table" => 1
"sofa" => 0
"refrigerator" => 1
"phone" => 1
"desk" => 1
"kitchen" => 1
"hairdryer" => 1
"beds" => 1
"kettle" => 1
"bathroom" => 1
"balcony" => 1
"air_conditioning" => 1
"lang" => "mk"
"discount_id" => 1
"language_id" => 1
"title" => "ПРЕМИЕР АПАРТМАНИ"
"description" => """
<p>Сонувајте додека се сместувате во нашиот апартман од 42м² опремен со кралски кревет (queen bed), простор за седење и Чајна кујна – мала кујничка. ▶
<br />
Големина на апартманот: 42м²</p>
"""
"name" => "mk"
"client" => array:12 [▶]
]
]
"first_page_url" => "http://booking.test/booking?page=1"
"from" => 1
"last_page" => 25
"last_page_url" => "http://booking.test/booking?page=25"
"next_page_url" => "http://booking.test/booking?page=2"
"path" => "http://booking.test/booking"
"per_page" => 2
"prev_page_url" => null
"to" => 2
"total" => 50
]
Can you give a few examples of columns in room_types?
"price_id"
"quantity"
"wifi"
"wardrobe"
"tv"
"table"
"sofa"
"title"
"description" ....
```
yes only id is 1 on to all rows
Does it make a difference if you change the order?
->select('room_types.*', 'bookings.*')
Otherwise try specifying each column that you need
if I add
->select('room_types.*', 'bookings.*')
to the sql I getting the wrtite id but no title, deescription ....
Sql is probably having problems with overlapping column names. Specify the columns you need the (you can use an array). Remember to add table names
Please or to participate in this conversation.