场景:
在git上clone一个项目代码吗laravel版本是5.6 php的版本是7.1 但是运行的时候一直提示错误
Call to undefined method Eachdemo\Rbac\RbacServiceProvider::loadFactoriesFrom()
解决办法:
给RbacServiceProvider,手动添加方法,如图所示,
<?php
namespace Eachdemo\Rbac;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
class RbacServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// 注册路由文件
$this->loadRoutesFrom(__DIR__.'/route/rbac.php');
// 注册数据库迁移文件
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
// 模型工厂
//$this->loadFactoriesFrom(__DIR__.'/database/factories');
$this->loadFactories();
}
protected function loadFactories()
{
// 假设你的工厂文件位于 database/factories/rbac 目录下
$factoryPath = __DIR__.'/../database/factories/rbac';
if (is_dir($factoryPath)) {
Factory::load($factoryPath);
}
}
}