且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何用雄辩的查询(laravel 4)?

更新时间:2023-11-17 18:30:34

您需要使用原始表达式所以你可以使用这样的特殊功能。

You need to use raw expressions so you can use special functions like that.

Model::select(DB::raw('substr(id, 1, 4) as id'))->groupBy(DB::raw('substr(id, 1, 4)'))->get();

其中模型是您想要的雄辩模型运行查询。

Where Model is your Eloquent model you want to run the query on.