use IFNULL in laravel I have a query in laravel which is working fine.

$subjects = $app-&gt;db-&gt;table('subjects')-&gt;LeftJoin('downloads', 'subjects.subjectID', '=', 'downloads.subject_id')
        -&gt;where('universityID', $currentUser-&gt;universityID)-&gt;where('semesterID', $currentUser-&gt;semesterID)-&gt;where('courseID', $currentUser-&gt;courseID)
        -&gt;select('subjects.subjectID', 'subjects.subjectName', 'subjects.price',  'downloads.is_download' )
        -&gt;orderBy('subjectID')
        -&gt;get();


There is only one issue that is_download comes null when there is no relative entry in table. After some research I found that there is a function IFNULL by using which I can change is_download null to 0. So here is my query which is not working. Blank screen is showing.

$subjects = $app-&gt;db-&gt;table('subjects')-&gt;LeftJoin('downloads', 'subjects.subjectID', '=', 'downloads.subject_id')
        -&gt;where('universityID', $currentUser-&gt;universityID)-&gt;where('semesterID', $currentUser-&gt;semesterID)-&gt;where('courseID', $currentUser-&gt;courseID)
        -&gt;select('subjects.subjectID', 'subjects.subjectName', 'subjects.price',  IFNULL( `downloads`.`is_download` , 0 ) )
        -&gt;orderBy('subjectID')
        -&gt;get();


I am able to write this query in my phpmyadmin but not know how to write in laravel

This is the api, So whole code looks like

use Illuminate\Database\Query\Expression as raw;
use project\Models\Subject;
use project\Models\Semester;
use project\Models\StudentRegistration;

$app-&gt;get('/api/getSubject/:studentID', function($studentID) use ($app) {
error_reporting(E_ALL);
    $currentUser = StudentRegistration::where('studentID', $studentID)-&gt;first();

$subjects = $app-&gt;db-&gt;table('subjects')-&gt;LeftJoin('downloads', 'subjects.subjectID', '=', 'downloads.subject_id')
        -&gt;where('universityID', $currentUser-&gt;universityID)-&gt;where('semesterID', $currentUser-&gt;semesterID)-&gt;where('courseID', $currentUser-&gt;courseID)
        -&gt;select('subjects.subjectID', 'subjects.subjectName', 'subjects.price',  IFNULL( `downloads`.`is_download` , 0 ) )
        -&gt;orderBy('subjectID')
        -&gt;get();
print_r($subjects);
    return $app-&gt;response-&gt;write(json_encode([
                'error' =&gt; 0,
                'subjects' =&gt; $subjects
    ]));
});
replace 

-&gt;select('subjects.subjectID', 'subjects.subjectName', 'subjects.price',  
IFNULL( `downloads`.`is_download` , 0 ) )


with

-&gt;select('subjects.subjectID', 'subjects.subjectName', 'subjects.price',  
DB:Raw(' IFNULL( `downloads`.`is_download` , 0 )') )


and add an alias

-&gt;select('subjects.subjectID', 'subjects.subjectName', 'subjects.price',  
DB:Raw(' IFNULL( `downloads`.`is_download` , 0 ) as is_download') )