PHP Fatal error in laravel DatabaseSeeder
Get the solution ↓↓↓Hi Guys im newly learning laravel so when i setup code to seed my tables in database, i get this error
Seeding: BearAppSeeder
PHP Fatal error: Call to undefined method Bear::create() in C:\Users\mrosh\Desktop\WD\garden\database\seeds\Database
Seeder.php on line 41
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined method Bear::create()
Here is my code in DatabaseSeeder.php file, the idea is to create table for 'bears', 'fish', 'trees' and 'picnics' and links bears to picnics "many-to-many" and seed them with some data
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
// call our class and run our seeds
$this->call('BearAppSeeder');
$this->command->info('Bear app seeds finished.'); // show information in the command line after everything is run
}
}
// our own seeder class
// usually this would be its own file
class BearAppSeeder extends Seeder {
public function run() {
// clear our database
so how i can fix this i have tried many things but all fails
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Solution:
Make sure yourBear
model extendsIlluminate\Database\Eloquent\Model
like this:
class Bear extends \Illuminate\Database\Eloquent\Model
otherwiseBear
model won't havecreate
method and you will get error that this method doesn't exist
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: string literal contains an unescaped line break
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.