播种机的命名空间
Namespacing for seeders
我想看看我的种子文件做错了什么,无法正确使用我的命名空间,我想看看是否有人能发现这段代码中有什么问题。
Error: PHP Fatal error: Class 'App\Models\Eloquent' not found in
/Users/me/Repositories/personal/project/app/models/Event.php
<?php
namespace App\Models;
class Event extends Eloquent {
protected $fillable = [];
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'events';
}
<?php
use App\Models\Event;
// Composer: "fzaninotto/faker": "v1.3.0"
use Faker\Factory as Faker;
class EventsTableSeeder extends Seeder {
public function run()
{
$faker = Faker::create();
foreach(range(1, 100) as $index)
{
Event::create([
]);
}
}
}
您需要指向根命名空间中的 Eloquent
而不是 App\Models
(不存在)
中的 Eloquent
要做到这一点,请使用反斜杠引用 id:
class Event extends \Eloquent {
或添加use
语句:
use Eloquent
class Event extends Eloquent {
我想看看我的种子文件做错了什么,无法正确使用我的命名空间,我想看看是否有人能发现这段代码中有什么问题。
Error: PHP Fatal error: Class 'App\Models\Eloquent' not found in /Users/me/Repositories/personal/project/app/models/Event.php
<?php
namespace App\Models;
class Event extends Eloquent {
protected $fillable = [];
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'events';
}
<?php
use App\Models\Event;
// Composer: "fzaninotto/faker": "v1.3.0"
use Faker\Factory as Faker;
class EventsTableSeeder extends Seeder {
public function run()
{
$faker = Faker::create();
foreach(range(1, 100) as $index)
{
Event::create([
]);
}
}
}
您需要指向根命名空间中的 Eloquent
而不是 App\Models
(不存在)
Eloquent
要做到这一点,请使用反斜杠引用 id:
class Event extends \Eloquent {
或添加use
语句:
use Eloquent
class Event extends Eloquent {