I want to generate dummy data using factory with seeder so it will give me the error.
when I run this command given below:
php artisan db:seed
so here it's the error.
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) in D:\xampp\htdocs\Bootstrap\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 1120 PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0
class DatabaseSeeder extends Seeder
{
public function run()
{
factory(User::class,5)->create()->each(function ($user){
$profile = factory(Profile::class)->make();
$user->profile()->save($profile);
$profile->each(function ($profiles){
$qualification =factory(Qualification::class,3)->make();
$experience =factory(Experience::class,3)->make();
$profiles->qualification()->saveMany($qualification);
$profiles->experience()->saveMany($experience);
});
});
}
}
For each User has-one Profile. For each Profile Has-many (Qualification and Experience).
If we run this code given below:
class DatabaseSeeder extends Seeder
{
public function run()
{
DB::table('posts')->insertOrIgnore([
['id'=>1,'title'=>'admission','created_at'=>now(),'updated_at'=>now()],
['id'=>2,'title'=>'biology','created_at'=>now(),'updated_at'=>now()],
['id'=>3,'title'=>'mathematics','created_at'=>now(),'updated_at'=>now()],
['id'=>4,'title'=>'chemistry','created_at'=>now(),'updated_at'=>now()],
['id'=>5,'title'=>'physics','created_at'=>now(),'updated_at'=>now()],
['id'=>6,'title'=>'english','created_at'=>now(),'updated_at'=>now()],
['id'=>7,'title'=>'urdu','created_at'=>now(),'updated_at'=>now()],
]);
DB::table('provinces')->insertOrIgnore([
['id'=>1,'title'=>'punjab','created_at'=>now(),'updated_at'=>now()],
['id'=>2,'title'=>'sindh','created_at'=>now(),'updated_at'=>now()],
['id'=>3,'title'=>'nwfp','created_at'=>now(),'updated_at'=>now()],
['id'=>4,'title'=>'balochistan','created_at'=>now(),'updated_at'=>now()],
]);
}
}
using this command php artisan db:seed
then there is no error received.
please help me in using a laravel factory.