mardi 21 février 2017

Laravel query asserting against wrong value specified

I have a very frustrating scenario, where I want to get all results where type = 2. Upon viewing this query in the view, it's showing where type = 5.

Eloquent function:

RequestModel::where('id', $object->pluck('id'))
    ->appointments()
    ->orderBy('created_at', 'asc')
    ->paginate('10');

Appointments scope:

public function scopeAppointments($query)
{
    return $query->where('type', '=', 2);
}

Snippet of query outputted on view:

from `requests` where `id` = '4' and `type` = '5'

If I remove the ->appointments() method, it removes the type = '5', so I know it's directly relating to it.

Even if I do not use a scope, and use a ->where('type', 2), it still returns 5.

If I put the type query directly into the first section, it works as expected, for example:

RequestModel::where('type', 2)
    ->orderBy('created_at', 'asc')
    ->paginate('10');

Why doesn't a second where query do as it's intended and why is it showing 5, when I explicitly have chosen 2!



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

Aucun commentaire:

Enregistrer un commentaire