mercredi 25 octobre 2017

Laravel use IF clause on MySQL column

How can I use MySQL IF on a column using Laravel? How can I optimize the following query to use Laravel's model or Query builder? Right now I'm using a raw query.

$contacts = ['88544','22455','66981']

DB::select('SELECT name, 
IF(file_path=null OR file_path=\'\',\'\',CONCAT("' . url("/media") . "/\",file_path)) AS profile_pic_url FROM users 
LEFT JOIN file_uploads on file_id=file_uploads.id WHERE 
(phone_number IN('" . implode("','", $contacts) . "') 
OR phone_number_full IN('" . implode("','", $contacts) . "')) ORDER BY name ASC");



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

Aucun commentaire:

Enregistrer un commentaire