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 :: how to remove array index from json in php 
Php :: get key of array element php 
Php :: php session variables 
Php :: combine 2 columns search query laravel 
Php :: guzzle get request 
Php :: shortcode php wordpress 
Php :: in_array associative array php 
Php :: fast excel export laravel 
Php :: php meta refresh 
Php :: set php var to html 
Php :: check duplicate data in array php 
Php :: Remove last symbol from string 
Php :: Clear and delete the folder after the time specified in php 
Php :: phpspreadsheet CellProtection 
Php :: laravel where not equal 
Php :: php remove non utf-8 characters 
Php :: delete button laravel 
Php :: wp_cache_get 
Php :: laravel drop table migration 
Php :: php append string 
Php :: TRANSACTON LARAVEL QUERY BUILDER 
Php :: laravel custom validation message 
Php :: laravel mail send to multiple recipients 
Php :: laravel carbon time format 
Php :: php error check 
Php :: magento 2 get number of cart items 
Php :: php mail in localhost wamp 
Php :: laravel DB wherein 
Php :: laravel How to capture output in a file from php artisan test 
Php :: wp php category page count products 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =