无法找到提供商"图像"与语言环境" en_US" fzaninotto / Faker播种时

时间:2015-05-15 15:18:49

标签: laravel-4 artisan

我尝试使用fzaninotto/Faker为我的数据库播种,但是当我运行php artisan db:seed时,我收到以下错误。

  

[InvalidArgumentException]
    无法找到提供商"图像"使用区域设置" en_US"

     

db:seed [--class [=&#34; ...&#34;]] [--database [=&#34; ...&#34;]] [--force] < / p>

我有三个应该执行的播种器类,并且都没有引用&#34;图像&#34; (没有表格,也没有名为Images的字段)。这是我在DatabaseSeeder

上的代码
class DatabaseSeeder extends Seeder {

    protected $tables = [
        'users','posts','feedbacks'
    ];
    protected $seeders = [
        'UsersTableSeeder',
        'PostsTableSeeder',
        'FeedbacksTableSeeder'
    ];
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Eloquent::unguard();

        $this->cleanDatabase();
        foreach ($this->seeders as $seedClass)
        {
            $this->call($seedClass);
        }

    }

    private function cleanDatabase()
    {
        DB::statement('SET FOREIGN_KEY_CHECKS=0');
        foreach ($this->tables as $table)
        {
            DB::table($table)->truncate();

        }
        DB::statement('SET FOREIGN_KEY_CHECKS=1');
    }
}

播种机类:

use Faker\Factory as Faker;
use Bicicletas\Feedbacks\Feedback;
use Bicicletas\Users\User;

class FeedbacksTableSeeder extends Seeder {
    public function run()
    {
        $faker = Faker::create();
        $usersIds = User::lists('id');
        $stars = array(1,2,3,4,5);

        foreach(range(1, 10) as $index)
        {
            Feedback::create([
                'user_id' => $faker->randomElement($usersIds, $count=1),
                'rating'  => $faker->randomElement($stars),
                'content' =>$faker->text($maxNbChars = 150),
                'created_at' =>$faker->dateTimeBetween($startDate = '-1 years', $endDate = 'now')

            ]);
        }
    }

}

use Bicicletas\Posts\Post;
use Faker\Factory as Faker;

class PostsTableSeeder extends Seeder {
    public function run()
    {
        $faker = Faker::create();

        foreach(range(1, 20) as $index)
        {
            Post::create([

            'title' => $faker->text($maxNbChars = 50),
            'slug'  =>   $faker->slug,
            'content' =>$faker->text($maxNbChars = 550),
            'created_at'=>$faker->dateTime()
            ]);
        }
    }
}


use Bicicletas\Users\User;
use Faker\Factory as Faker;

class UsersTableSeeder extends Seeder {

    public function run()
    {
        $faker = Faker::create();

        foreach(range(1, 20) as $index)
        {
            User::create([
                'firstname' => $faker->firstName,
                'lastname' =>$faker->lastName,
                'country' =>$faker->country,
                'email' =>$faker->email,
                'avatar'=>"$index.jpg",
                'password' =>'secreto'
            ]);
        }
    }

}

我之前尝试过这个并且它有效。你能否解释一下这个错误?

1 个答案:

答案 0 :(得分:0)

当播种时错误被抛出并不是因为它与种子有“做什么”,而是因为Laravel在播种时执行它的引导程序并且你对该包有问题。

如果您已关注the official guide,则需要在config/app.php中添加以下内容:

  • 添加到$providers

    'Intervention\Image\ImageServiceProvider'
    
  • 添加$alias

    'Image' => 'Intervention\Image\Facades\Image'
    

由于您已经完成了(根据您的意见),您可能需要发布包的配置:

$ php artisan config:publish intervention/image

有一个GitHub issue用户遇到了这个问题。他们中的一些人使用composer dumpautoload解决了这个问题,其他人则遇到了问题,因为他们的模型名为Image。所以,如果这不能解决您的问题,请查看该问题,这可能会有所帮助。