dimanche 6 novembre 2016

subquery inside select of Laravel with Eloquent ORM

I want to execute following raw query with laravel eloquent ORM: SELECT *,(SELECT country FROM tbl_sim_numbers WHERE highland_id= b.highland_id) as country1,(SELECT operator FROM tbl_sim_numbers WHERE highland_id= b.highland_id) AS operator1 FROM tbl_sim_distributions b ORDER BY b.created_at

on eloquent ORM of laravel. I tried:

$sub = DB::select(DB::raw("SELECT *,(SELECT country FROM tbl_sim_numbers WHERE highland_id= b.highland_id) as country1,(SELECT operator FROM tbl_sim_numbers WHERE highland_id= b.highland_id) AS operator1 FROM tbl_sim_distributions b
                 ORDER BY b.created_at"));

        $pdfGenObjForList = DB::table( DB::raw("({$sub->toSql()}) as sub") )
            ->mergeBindings($sub->getQuery());

However above code gives error.Someone,please help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire