Mathieu Mourareau
Mathieu Mourareau

Reputation: 1220

Query with eloquent or Where clause

This query return me not the right values .

everything is going well till $query->where('valid_licence_id', '1') but when i add :

->where('statut_licence_id' , '4') ->orWhere('statut_licence_id' , '1');

the query display me the result with 'valid_licence_id = 3 and not 1 . someone now here i'm doing wrong ? thanks a lot in advance

$licencies = Licencies::where(['structure_id' => Auth::user()->structure->id])
            ->where(function ($query) {
                $query->where('valid_licence_id', '1')
                ->where('statut_licence_id' , '4')
                ->orWhere('statut_licence_id' , '1');
            })->orderBy('created_at', 'DESC')->paginate(10);
        return view('licencie/notConfirmed', compact('licencies'));

Upvotes: 1

Views: 263

Answers (1)

EddyTheDove
EddyTheDove

Reputation: 13259

Place this

->where('valid_licence_id', '1')

Out of the closure.

->where('valid_licence_id', '1')
->where(function ($query) {
    $query->where('statut_licence_id' , '4')
    ->orWhere('statut_licence_id' , '1');
})->orderBy('created_at', 'DESC')->paginate(10);

Upvotes: 3

Related Questions