Reputation: 788
I have the following query
Event::where('event_name', $event_id)
->orWhere('id', $event_id)->first();
The $event_id can be a alpha-numeric string (event_name) or an integer (id - primary key). The orWhere statement takes priority over the where statement everytime unless the orWhere statement fails.
For example, the following query gets an event with id = 601, eventhough there is an event that has an event_name = 601a35e0ebee30
with id = 1070.
Event::where('event_name', "601a35e0ebee30")
->orWhere('id', "601a35e0ebee30")->first();
P.S. When I use Event::find("601a35e0ebee30")
, it returns an event with id of 601
Upvotes: 0
Views: 408
Reputation: 81
use nested array
Event::where([['event_name', $event_id]])->orWhere([['id', $event_id]])->first();
Upvotes: 0
Reputation: 1
Please try this one.
Event::where(function($query) use ($event_id){
$query->where('event_name', $event_id);
$query->orWhere('id', $event_id);
})->first();
Upvotes: -1