How to write Subquery in Select statement laravel 5.1?
<p>How to write this query in laravel 5.1</p>

<pre><code>SELECT 
     (SELECT firstname FROM registration_details a INNER JOIN users b 
        ON a.id = b.registerid
        WHERE c.patientid = b.id ) AS patient,
     (SELECT firstname FROM registration_details a INNER JOIN users b 
        ON a.id = b.registerid 
        WHERE c.doctorid = b.id ) AS doctor, 
    c.`appoinmentdate`
FROM `appoinments` c
</code></pre>

<p>I tried like this But i get Undefined property: stdClass::$id  error</p>

<pre><code> DB::table('appoinments')
   -&gt;select(DB::raw(
       "(SELECT firstname FROM registration_details INNER JOIN users ON      registration_details.id = users.registerid WHERE appoinments.patientid =    users.id) AS patient",
       "(SELECT firstname FROM registration_details INNER JOIN users ON registration_details.id = users.registerid WHERE appoinments.doctorid = users.id) As doctor",
       "appoinments.appoinmentdate",
       "appoinments.id",
       "(SELECT timings FROM appoinment_time WHERE appoinment_time.id = appoinments.appoinment_time) AS apptime ",
       "(SELECT branchname FROM branches WHERE branches.id = appoinments.branchcode) AS branch"))
  -&gt;get();
</code></pre>