【发布时间】:2023-03-07 10:51:01
【问题描述】:
我正在尝试为我的数据库播种,但是当我使用 modelName::create() 或 $modelName->save() 时出现问题。 我有这种错误
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"调用未定义的方法 Doc::save()","file":"/Applications/ MAMP/htdocs/Doc_project/app/database/seeds/DatabaseSeeder.php","line":45}
或
调用未定义的方法 Doc::create()
但我不知道为什么。
我的模特:
class Doc extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'doc';
protected $fillable = array('creators_name', 'type_document', 'title', 'description');
public function steps(){
return this->hasMany('Step')
}
public function tags(){
return this->belongsToMany('Tag', 'doc_tag', 'id_doc', 'id_tag')
}
}
我的播种机:
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
$this->call('DocAppSeeder');
$this->command->info('Doc app seeds finished.'); // show information in the command lin }
}
}
class DocAppSeeder extends Seeder {
public function run(){
DB::table('doc')->delete();
DB::table('step')->delete();
DB::table('tag')->delete();
DB::table('doc_tag')->delete();
/* DB::table('doc')->insert(array(
'creators_name' => 'Alexis',
'type_document' => 'Solution',
'title' => 'NoAD Printer',
'description' => 'Installation imprimante en NoAd'
));*/
$doc = new Doc;
$doc->creators_name = 'Alexis';
$doc->type_document = 'Solution';
$doc->title = 'NoAD Printer';
$doc->description = 'Installation imprimante en NoAd';
$doc->save();
/*$docTest = Doc::create(array(
'creators_name' => 'Alexis',
'type_document' => 'Solution',
'title' => 'NoAD Printer',
'description' => 'Installation imprimante en NoAd'
));
}
}
我尝试使用DB::Table(...)->insert(...)它可以工作,但我不能使用它,因为我需要获取每个对象的一些信息
有人有想法吗? 谢谢你
【问题讨论】:
-
@Cheery 你是说他的
Doc模型由于缺少()而没有被实例化吗?因为它们是可选的,除非您将参数传递给要实例化的类的构造函数。 -
没有变化
-
还有,你完成了吗
composer dump-autoload -
@Ohgodwh,我已经完成了