• 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

Reducing authentication calls on external API (Laravel 5.6)

Laravel PackageManifest.php: Undefined index: name

How can i hide dt if dd got empty value

WooCommerce Subscriptions: Remove role on cancelled subscription

disable two buttons after clicking another button

Creating command to backup MySql database in Laravel

Target Laravelista is not instantiable

phpunit - testing is painfully slow

Display a success custom notice after Placing an Order in WooCommerce

SlimExceptionHttpNotFoundException

Mysqli multi query error

Whats the point of running Laravel with the command 'php artisan serve'?

Inserting Country Selection into MySQL PHP [duplicate]

Laravel dosen't connect with Oracle

With doctrine ODM, can I embed many subdocuments in a main document?

About Contact Privacy policy Terms and conditions