Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gedeon98's avatar

Eloquent method to find id

Hello! I am trying to find the "id" of booking for a particular time, this is what I have at the moment:

Booking::where('timeslot', '=', $reservation->reservation_time);

Is there a method to chain to get "id"? Thanks in advance!

0 likes
7 replies
Snapey's avatar

add a get() to it, then you have the entire booking, you can then access the id or anything else you need,

Bear in mind that this will return a collection, so you could have multiple entries all with the same timeslot

Prokosa's avatar
$items=Booking::where('timeslot', '=', $reservation->reservation_time)->pluck( 'id' )
			->toArray();
Snapey's avatar
Snapey
Best Answer
Level 122

@prokosa can be shortened to

$items=Booking::where('timeslot', '=', $reservation->reservation_time)->get()->modelKeys();
2 likes
Snapey's avatar

Not sure what you are doing here, or what $date contains.

I do notice though that whatever the outcome of your @if statement, you output identical data

Snapey's avatar

ok, but you did not respond to either of my previous points?

Please or to participate in this conversation.