简体   繁体   English

如何在没有Laravel的情况下使用雄辩的ORM?

[英]How to use Eloquent ORM without Laravel?

是否可以在没有Laravel的情况下使用Eloquent?或者有人知道同样容易使用的ORM吗?

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. 不久前,Dan Horrigan发布了一个名为Laravel 4的Capsule软件包,该软件包使Eloquent可以独立使用,而无需进行任何设置。 The package itself has been merged with the L4 core so you no longer need to use the package. 该软件包本身已与L4核心合并,因此您不再需要使用该软件包。

If you refer to the illuminate/database repository 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. 此后,Dan Horrigan删除了他的Capsule实现,因为它已直接内置到Eloquent中。 Refer to the above illuminate/database link for more details on how to use Capsule. 有关如何使用Capsule的更多详细信息,请参阅上面的illuminate/database链接。

In Laravel 4.*, Eloquent is automatically independent because it's shipped with Dan Horrigan's Capsule. 在Laravel 4. *中,Eloquent是自动独立的,因为它与Dan Horrigan的Capsule一起提供。 You don't need to download any extras. 您无需下载任何其他功能。 For a how to please visit: https://github.com/illuminate/database/blob/master/README.md 有关如何访问的信息,请访问: https : //github.com/illuminate/database/blob/master/README.md

Check out https://github.com/Luracast/Laravel-Database it provides full eloquent support including artisan migrations and 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 披露:我是此存储库的作者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM