代码之家  ›  专栏  ›  技术社区  ›  Syamsoul Azrien

Laravel-选择临时列,其中临时列

  •  0
  • Syamsoul Azrien  · 技术社区  · 6 年前
    $search_str = "full name search";
    
    $user = App\User::selectRaw("CONCAT(`f_name`, `l_name`) AS `fullname`")
            ->where('fullname', 'LIKE', '%$search_str%')
            ->get();
    

    根据上面的代码,列 fullname 全名 列只是一个临时列。

    where 子句,Laravel返回错误:

    2 回复  |  直到 6 年前
        1
  •  2
  •   Jerodev    6 年前

    你可以使用 CONCAT

    $search_str = "full name search";
    
    $user = App\User::selectRaw("CONCAT(`f_name`, `l_name`) AS `fullname`")
        ->whereRaw("CONCAT(`f_name`, `l_name`) LIKE '%?%'", [$search_str])
        ->get();
    
        2
  •  0
  •   Nishabh Mistry    6 年前

    使用Having作为别名。请参阅下面的参考链接。

    https://laravel.com/docs/5.6/queries#ordering-grouping-limit-and-offset