laravel 使用concat 拼接列

 

laravel 在处理结果集的列的时候需要用到。

$ptList = DB::table(xx) ->select(‘id’,’name’,DB::raw(‘CONCAT(“images/PTgame/”,gameid,”.jpg”) as gameid’),’type’)
       ->where(function ($query) use ($gameName, $gameType) {          

  if ($gameName != ”) {                    $query->where(‘name’, ‘like’, ‘%’ . $gameName . ‘%’);                }              

if ($gameType != ”) {                    $query->where(‘type’, $gameType);                            })         

  ->groupBy(‘name’)            ->get();

 

Leave a Reply

Your email address will not be published. Required fields are marked *