PHP-尝试为数据库播种时出现错误
作者:互联网
当我尝试使用fakerr在laravel 5.4中播种数据库时遇到错误
use Illuminate\Database\Seeder;
use app\PostModell;
class postcarseeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// Let's truncate our existing records to start from scratch.
PostModell::truncate();
$faker = \Faker\Factory::create();
// And now, let's create a few articles in our database:
for ($i = 0; $i < 50; $i++) {
PostModell::create([
'title' => $faker->sentence,
'body' => $faker->paragraph,
]);
}
}
上面是我的种子类,它使用以下命令$this-> call(postcarseeder :: class)调用我的DatabaseSeeder.php.这样我就可以运行php artisan db:seed
解决方法:
您应该使用完整的名称空间:
App\PostModell
或将其添加到seeder类的顶部:
use App\PostModell;
标签:laravel-5-4,laravel,php 来源: https://codeday.me/bug/20191025/1928467.html