我已经尝试过我能想到的一切,但似乎无法解决这个问题,我确定它是一件很小的东西,我应该能够解决这个问题,但它有我很难过。
我已经运行了composer dump-autoload但收效甚微。
每当我使用artisan db:seed
命令时,我都会收到以下错误:
PHP致命错误:Class' App \ Models \ Company'找不到 X:\ Development \ laravelApplication \ database \ seeds \ DatabaseSeeder.php on 第60行
应用程序/ HTTP /型号/ Company.php
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Company extends Model {
//
public function configurations() {
return $this->hasMany('App\Models\Configuration');
}
public function users() {
return $this->hasMany('App\Models\Users');
}
public function admins() {
return $this->users()->where('admin', 1)->get();
}
}
数据库/种子/ DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\Models\Company;
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call('CompaniesTableSeeder');
$this->command->info('Companies table seeded!');
$this->call('UserTableSeeder');
$this->command->info('User table seeded!');
}
}
/**
* Seed the Users table
* @return void
*/
class UserTableSeeder extends Seeder
{
function run()
{
$needlers_id = Company::where('name', 'Needlers LTD')->first()->id;
DB::table('users')->delete();
User::create([
'company_id' => $needlers_id,
'name' => 'Joe Ware',
'email' => 'joe.ware@needlers.co.uk',
'password' => 'needlers123',
'phone' => '07123456789',
'admin' => 1,
'screen' => 0,
]);
}
}
/**
* Seed the Users table
* @return void
*/
class CompaniesTableSeeder extends Seeder
{
function run()
{
DB::table('companies')->delete();
Company::create([
'name' => 'Company name',
'tier' => 'platinum'
]);
}
}
有人可以指出我遗失/做错了什么吗?
答案 0 :(得分:1)
尝试使用它:
Company::create([
'name' => 'Needlers LTD',
'tier' => 'platinum'
]);
或者:
\App\Models\Company::create([
'name' => 'Needlers LTD',
'tier' => 'platinum'
]);
而不是:
App\Models\Company::create([
'name' => 'Needlers LTD',
'tier' => 'platinum'
]);
另外,请确保自动加载Models命名空间,在composer.json
中使用以下内容:
"autoload": {
"classmap": [
"database",
"app/Models"
],
答案 1 :(得分:0)
试试吧
composer dump
跑完后。
php artisan db:seed