mercredi 18 avril 2018

Laravel if then condition

I have this query

        $query = Model::Select('table1.col1','table1.col2','table1.col3')
        ->join('table2', 'table1.id', '=', 'table2.id')            
        ->select('table1.id','table2.logo','table1.col2','table1.col3')
        ->whereIn(....)
        ->whereIn(....);

that works fine. The extra thing that i want to add is this: If col2 value of table1 is 0 then i want to get the value of table1.col3 But when col2 value of table 1 is 1 i want to select from another table.

something like IF table1.col2 = 0 returned_value = table1.col3 ELSE returned_value = (SELECT other_value FROM table3 WHERE CONDITION)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire