mercredi 30 septembre 2020

How to write if elseif else condition laravel query builder?

Below is my query,

rows = "SELECT * FROM `table` WHERE score = 1"
if (rows.Count < 3) //at least one row
return if;
else if(rows.Count >7)
return 'else if';
else
return 'else';

How to write above query with when using querybuilder laravel. Actually I want to know about how to write else condition.

Below is my code;

$query=DB::table('aaa')
->select('*')
->when($count<3,function ($q){
    echo 'if';
})
->when($count>7,function ($q){
    echo 'else if';
})

///I dont know how to write else condition here


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire