問題描述
是否可以在沒有 Laravel 的情況下使用 Eloquent 或者是否有人知道同樣易于使用的 ORM?
Is it possible to use Eloquent without Laravel or does somebody knows a equally easy to use ORM?
推薦答案
是的,你可以.不久前,Dan Horrigan 為 Laravel 4 發布了一個名為 Capsule 的包,它允許 Eloquent 獨立使用,并且最少設置.該包本身已與 L4 核心合并,因此您不再需要使用該包.
Yes you can. A while ago Dan Horrigan released a package called Capsule for Laravel 4 which allowed Eloquent to be used independently and with minimal setup. The package itself has been merged with the L4 core so you no longer need to use the package.
如果您參考 illuminate/database 存儲庫,這里有一個關于使用 Eloquent 的不錯的小介紹,沒有框架.
If you refer to the illuminate/database repository there is a nice little introduction on using Eloquent without the framework.
這是啟動和運行的一小段摘錄.
Here is a small excerpt of getting it up and running.
$capsule = new IlluminateDatabaseCapsule($config);
$capsule->bootEloquent();
$capsule->connection()->table('users')->where('id', 1)->first();
更新
Dan Horrigan 從那以后刪除了他的 Capsule 實現,因為它現在直接內置到 Eloquent 中.有關如何使用 Capsule 的更多詳細信息,請參閱上面的 illuminate/database
鏈接.
Dan Horrigan has since removed his Capsule implementation as it is now built directly into Eloquent. Refer to the above illuminate/database
link for more details on how to use Capsule.
這篇關于如何在沒有 Laravel 的情況下使用 Eloquent ORM?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!