• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Laravel 8 factory state afterCreating

phplaravellaravel-7laravel-8


PHP Snippet 1:

public function active()
{
    return $this->state(function (array $attributes) {
        return [
            'active' => true,
        ];
    })->afterCreating(function (User $user) {
        // ...
    });
}

PHP Snippet 2:

public function active()
    {
        return $this->state([
            'active' => true,
        ])->afterCreating(function (Article $user) {
            // ...
        });
    }

PHP Snippet 3:

    public function configure()
    {
        return $this->afterCreating(function (User $user) {
            //
        });
    }

Related Snippets

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

How to set a domain name with php artisan serve

storagelogs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied

laravel automatically deletes server.php on php artisan serve

PHP error: "The zip extension and unzip command are both missing, skipping."

Open a popup box after receiving result from ajax

Composer Warning: openssl extension is missing. How to enable in WAMP

Laravel Carbon get start + end of last week?

Match single unknown parameter php (Morse-code Regex)

VichUploaderBundle error "Expected argument of type "File", "NULL" given" when submitting the form without selecting any file

Warning: sqlite_query() expects parameter 1 to be resource, string given

generating a random code in php?

Filter WooCommerce related products by Polylang language

How to get unique slug to same post-title for other time too?

PHPSpreadsheet - How Do I Use Auto Migration Tool

About Contact Privacy policy Terms and conditions