Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用 Eloquent ORM 执行以下选择语句:
SELECT LEFT(title, 200) AS excerpt FROM table WHERE id = 1;
重要的部分是LEFT(...) AS excerpt. 是否有某种函数(left() 不存在)允许这样的选择?如果没有,我该如何实施?
LEFT(...) AS excerpt
我想出了一个解决方案。如果有更简洁的方法,请告诉我,否则我将使用以下代码:
Post::select(DB::raw('LEFT(title, 200) AS excerpt'))->get();
Post是 Eloquent 模型的名称。
Post