lumen安装orangehill/iseed遇到的问题
一、我的版本和环境
系统win10 , 环境:集成环境phpstudy lumen: (7.2.1) (Laravel Components ^7.0)
二、起因
使用lumen协作开发,本地环境的测试数据最好是生成一个seed文件然后就可以让同事一起使用测试数据开发了,不用再用手填写测试数据。
三、遇到的问题
使用lumen开发当然是,先添加安装composer包了。
我们在这里使用
orangehill/iseed
安装命令:
composer require orangehill/iseed
安装完成之后测试下:
运行:php artisan iseed users
我这里使用了users表做测试
结果显示:
Command "iseed" is not defined.
解决方法,注册引入 Orangehill\Iseed 包。
我的在 bootstrap/app.php 文件中添加
$app->register(Orangehill\Iseed\IseedServiceProvider::class);
然后再运行
运行:php artisan iseed users
显示:
Call to undefined method Laravel\Lumen\Application::booting()
找到这个方法:
在vendor/orangehill/iseed/src/Orangehill/Iseed/IseedServiceProvider.php的register()方法中。
改动如下:
public function register()
{
$this->registerResources();
$this->app->singleton('iseed', function($app) {
return new Iseed;
});
// var_dump(method_exists ($this->app,'boot'));die;
$this->app->boot(function() { // todo 将booting改成boot即可
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Iseed', 'Orangehill\Iseed\Facades\Iseed');
});
$this->app->singleton('command.iseed', function($app) {
return new IseedCommand;
});
$this->commands('command.iseed');
}
再运行命令
运行:php artisan iseed users
结果显示:
In IseedCommand.php line 163:
Class 'Config' not found
和
In IseedCommand.php line 96:
Class 'File' not found
解决方式:
文件位置:vendor/orangehill/iseed/src/Orangehill/Iseed/IseedCommand.php
注意:用到这两个类的地方需要将他前面的 「 \ 」 去掉。
将类正确引入即可。我这里引入的两个类分别是。
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\File;
修改之后的两个地方:
最后再运行
php artisan iseed users
- 成功
显示:
php artisan iseed users
File UsersTableSeeder.php already exist. Do you wish to override it? [yes|no] (yes/no) [no]:
> yes
Created a seed file from table users
结束
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: