简体   繁体   English

将laravel应用程序转换为流明

[英]Converting a laravel application to lumen

So, I have been building a laravel 5.1 API and after months of work on it it dawned on me that I should have been using Lumen all along. 所以,我一直在构建一个laravel 5.1 API,经过几个月的工作,我突然意识到我应该一直使用Lumen。

Is there a way to convert a laravel app to a lumen app? 有没有办法将laravel应用程序转换为流明应用程序?

Lumen is essentially a stripped down version of Laravel. Lumen基本上是Laravel的精简版。 The application structure is the same, so as far as that goes it should be safe to create a new Lumen app and copy the app directory from your Laravel app. 应用程序结构是相同的,所以就此而言,创建一个新的Lumen应用程序并从Laravel应用程序复制app目录应该是安全的。

However, for performance reasons, Lumen does not have all the Laravel goodies working out of the box, and some are not there at all. 然而,出于性能原因,Lumen没有开箱即用的所有Laravel好东西,有些根本就没有。 So depending on how you've implemented you're Laravel app, here's a few things that you might need to change in order to migrate your app: 因此,根据您实施Laravel应用程序的方式,以下是您可能需要更改的一些内容,以便迁移您的应用:

  • Route definitions will have to be migrated because Lumen uses a different router 必须迁移路由定义 ,因为Lumen使用不同的路由器
  • Lumen does not use the .env file by default , so you need to uncomment the line Dotenv::load() in bootstrap/app.php if you want it to work 默认情况下 ,Lumen 不使用.env文件 ,因此如果你想让它工作,你需要取消注释bootstrap/app.php Dotenv::load()
  • Facades such as DB , Mail , Queue are also not enabled by default. 默认情况下,也不启用DBMailQueue等外观。 You can enable them by uncommenting $app->withFacades() in bootstrap/app.php . 您可以通过在bootstrap/app.php取消注释$app->withFacades()来启用它们。 However, even if you do enable them you only get a portion of the facades that you get in Laravel 但是,即使您启用它们,您也只能获得 Laravel中的一部分外墙
  • Eloquent needs to be enabled by uncommenting $app->withEloquent() in bootstrap/app.php 需要通过在bootstrap/app.php取消注释$app->withEloquent()来启用$app->withEloquent()

I've probably not covered everything, but this is to offer an idea on what you should be looking out for. 我可能没有涵盖所有内容,但这是为了提供一个关于你应该注意什么的想法。 All those things can be enabled, but the performance benefits Lumen brings are mostly because those things are disabled to get rid of that overhead, so try to modify your application wherever possible to make use of what Lumen offers by default. 所有这些都可以启用,但是Lumen带来的性能优势主要是因为那些东西被禁用以消除这些开销,所以尝试尽可能修改你的应用程序以利用默认提供的Lumen。

假设您使用的所有内容都在Lumen文档中并且实际可用于Lumen,您应该能够创建一个新的Lumen项目并将您的应用程序文件夹从Laravel拖放到新的Lumen项目中。

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

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