php - Laravel Call to undefined method create() and save() -
i'm trying seed db have problem when utilize modelname::create() or $modelname->save(). have kind of error
{"error":{"type":"symfony\component\debug\exception\fatalerrorexception","message":"call undefined method doc::save()","file":"/applications/mamp/htdocs/doc_project/app/database/seeds/databaseseeder.php","line":45}
or
call undefined method doc::create()
but dont know why.
my model :
class doc extends eloquent { /** * database table used model. * * @var string */ protected $table = 'doc'; protected $fillable = array('creators_name', 'type_document', 'title', 'description'); public function steps(){ homecoming this->hasmany('step') } public function tags(){ homecoming this->belongstomany('tag', 'doc_tag', 'id_doc', 'id_tag') } }
my seeder :
class databaseseeder extends seeder { /** * run database seeds. * * @return void */ public function run() { eloquent::unguard(); $this->call('docappseeder'); $this->command->info('doc app seeds finished.'); // show info in 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' )); } }
i seek db::table(...)->insert(...)
it works, can't utilize because need info on each object
someone have idea? give thanks
it looks php using different global level doc
class 1 think is. maybe facade or alias (self link, contains details instructions on how debug facade issues)?
regardless, best course of study of action see php thinks class is. in seeder, right before save
, include next debugging code
$r = new reflectionclass('doc'); var_dump( $r->getfilename() ); var_dump( $r->getname() );
this tell full-name of class (if it's alias) , class defined. guess class think doc
not eloquent model, , is, in fact, different class.
based on comments below, sounds someone's defined class named doc
in
/applications/mamp/htdocs/doc_project/app/database/migrations/2014_10_12_201016_doc.php
this isn't normal -- although it's easy see how might have happened. used artisan command create migration this
php artisan migrate:make doc
by not using more explicate form
php artisan migrate:make create_doc_table
you inadvertently create migration class same name model. seek recreating migration less specific name, , should set.
php laravel
No comments:
Post a Comment