Laravel / PHP一种将查询组合成一个查询的方法,或者一种更好的方法,返回单个变量

时间:2018-08-27 05:20:35

标签: php mysql sql laravel datatables

$diamonds = DB::connection('pgsql')->select("select * from diamonds limit 50"); //gets diamonds

$dia = DB::connection('pgsql')->select("select dia_val || dia_type as diacol from diamonds limit 50");//returns green or red in a new column diacol

$newdiamonds = array();
foreach($dia as $r){
    $singlediamond=$r->diacol;
    $newdiamonds[]=$this->get_diamond_status($singlediamond);  //looping through and getting whether it is emerald or ruby in array
}

function get_diamond_status(mydiamond){
    if(mydiamond=='green'){
         return 'emerald'
       }
    if(mydiamond=='red'){
         return 'ruby'
       }
}

return  view('/diamonds')->with('diamonds',$diamonds)->with('newdiamonds',$newdiamonds);

我想要一种方法,可以将一个变量发送到包含所有数据或所有列的视图

0 个答案:

没有答案