Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel factory relationship one to many

// parent factory 

    public function configure()
    {
        return $this->afterCreating(function (Category $category) {
            $posts = Post::factory(50)->make();
            $category->posts()->saveMany($posts);
        });
    }

// call in seeder
Category::factory(10)->create();
Comment

PREVIOUS NEXT
Code Example
Php :: check if array is empty php 
Php :: strict types php 
Php :: laravel use global variable in model 
Php :: how to enable pretty url in yii2 
Php :: file_put_contents error in laravel 
Php :: php proper function comments 
Php :: custom pagination laravel css 
Php :: excel return integer from date column laravel 
Php :: laravel mail send flexible subject 
Php :: cakephp 4 change layout view in a method 
Php :: cookies php syntax 
Php :: contact form 7 checkbox2 
Php :: pdf watermark dengan laravel 
Php :: php artisan make :migration with model 
Php :: autoload file laravel 
Php :: php custom autoload 
Php :: category title in post 
Php :: advantages of php 
Php :: remove colon and white space in a string by php 
Php :: upload images php mysql 
Php :: wp php category page count products 
Php :: curl error (code 3) url malformed laravel 
Php :: set only allow post request to a page - php 
Php :: how to clear php form data after submit 
Php :: $loop laravel list 
Php :: echo in console command laravel 
Php :: how to redirect to another page in php after submit 
Php :: replace word in string php 
Php :: symfony messenger route 
Php :: get the number of affected rows in php using pdo update statement 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =