dimanche 3 avril 2016

Advanced Where Clause In Laravel

I have an issue with my query in Laravel eloquent, I do not get results when I run the query and the generated query does not seem to be what I expect.

This is the code in controller:

$lastUpdate = Input::get('last_update');
$userId = Auth::user()->id;

$eventIds = EventVendor::where('user_id', $userId)
                    ->where('is_active', 1)->get()->lists('event_id');

$events = EventDetails::whereIn('id', $eventIds)
                    ->where(function($query) use ($lastUpdate) {
                        $query->where('created_at', $lastUpdate);
                        $query->orWhere('updated_at', $lastUpdate);
                    })
                    ->where('is_active', 1)
                    ->with("details_sub")
                    ->with("extras")
                    ->with("chargesDiscounts")
                    ->toSql();

This is the query that is generated:

select * from `mtgh_event_details` 
    where `mtgh_event_details`.`deleted_at` is null 
        and 0 = 1 
        and (`created_at` = ? or `updated_at` = ?) 
        and `is_active` = ?

Apart from the 0 = 1 which isn't supposed to be in there I do not see the full query either.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1VnfStv
via IFTTT

Aucun commentaire:

Enregistrer un commentaire