Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel seeding with relationships

//create 10 users
factory(User::class, 10)->create()->each(function ($user) {
    //create 5 posts for each user
    factory(Post::class, 5)->create(['user_id'=>$user->id]);
});
Comment

laravel seeder with relationships

factory(User::class, 10)->create()->each(function ($user) {
    $user->posts()->saveMany(factory(Posts::class, 5)->make());
});
Comment

laravel seeder with relationship

use AppModelsUser;
 
/**
 * Run the database seeders.
 *
 * @return void
 */
public function run()
{
    User::factory()
            ->count(50)
            ->hasPosts(1)
            ->create();
}
Comment

PREVIOUS NEXT
Code Example
Php :: php input onchange 
Php :: MySQL table in new page after click php 
Php :: number text short in laravel 
Php :: Add Text After or Before on the Shop Page/Archive Page 
Php :: PHP stripcslashes — Un-quote string quoted with addcslashes() 
Php :: Simple factory Design pattern in PHP 
Php :: A Livewire component was not found 
Php :: Regex to remove span tags using php [duplicate] 
Php :: laravel https middleware 
Php :: append single quote around variable in php string 
Php :: how to check ia folder if no have files in php 
Php :: guarded and fillable in laravel 
Php :: codeigniter 4 radio button isset 
Php :: kill php-fpm inside docker 
Php :: install composer laravel 
Php :: public variable in php 
Php :: multiple primary key defined laravel 
Php :: get last name user 
Php :: bootstrap autocomplete example laravel 
Php :: debugger in laravel 
Php :: 20 usd to php 
Php :: get month days in php 
Php :: PHP sprintf — Return a formatted string 
Php :: octobercms mail view 
Php :: laravel return a single dimensional array 
Php :: dropdown search php mysql 
Php :: laravel where condition with if 
Php :: laravel collection nth method 
Php :: laravel route limit parameter 
Php :: how to integrate google reCAPTCHA in codeigniter? 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =