use IFNULL in laravel
<p>I have a query in <code>laravel</code> which is working fine.</p>

<pre><code>$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();
</code></pre>

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

<pre><code>$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();
</code></pre>

<p>I am able to write this query in my phpmyadmin but not know how to write in <code>laravel</code></p>

<p>This is the api, So whole code looks like</p>

<pre><code>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
    ]));
});
</code></pre>