php 如何在没有 Laravel 的情况下使用 Eloquent ORM?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16633893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Eloquent ORM without Laravel?
提问by Andre Zimpel
Is it possible to use Eloquent without Laravel or does somebody knows a equally easy to use ORM?
是否可以在没有 Laravel 的情况下使用 Eloquent 或者是否有人知道同样易于使用的 ORM?
回答by Jason Lewis
Yes you can. A while ago Dan Horrigan released a package called Capsulefor 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.
是的你可以。不久前,Dan Horrigan为 Laravel 4发布了一个名为Capsule的软件包,它允许 Eloquent 以最少的设置独立使用。该软件包本身已与 L4 核心合并,因此您不再需要使用该软件包。
If you refer to the illuminate/databaserepository there is a nice little introduction on using Eloquent without the framework.
如果你参考illuminate/database存储库,这里有一个关于在没有框架的情况下使用Eloquent 的很好的介绍。
Here is a small excerpt of getting it up and running.
这是启动和运行它的一小段摘录。
$capsule = new Illuminate\Database\Capsule($config);
$capsule->bootEloquent();
$capsule->connection()->table('users')->where('id', 1)->first();
Update
更新
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.
Dan Horrigan 此后删除了他的 Capsule 实现,因为它现在直接内置到 Eloquent 中。illuminate/database
有关如何使用 Capsule 的更多详细信息,请参阅上面的链接。
回答by Nick
In Laravel 4.*, Eloquent is automatically independent because it's shipped with Dan Horrigan's Capsule. You don't need to download any extras. For a how to please visit: https://github.com/illuminate/database/blob/master/README.md
在 Laravel 4.* 中,Eloquent 自动独立,因为它与 Dan Horrigan 的 Capsule 一起提供。您无需下载任何额外内容。方法请访问:https: //github.com/illuminate/database/blob/master/README.md
回答by Arul Kumaran
Check out https://github.com/Luracast/Laravel-Databaseit provides full eloquentsupport including artisanmigrationsand more? for the latest Laravel 5.2.*
components.
查看https://github.com/Luracast/Laravel-Database它提供了完整的雄辩支持,包括工匠迁移等等?对于最新的Laravel 5.2.*
组件。
It uses capsule and lazy loads the components when they are used.
它使用胶囊并在使用时延迟加载组件。
Disclosure: I'm the author of this repository
披露:我是这个存储库的作者