• 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

Unit (real unit test) of test laravel relationship

How can I access an array/object?

Laravel - Implicit route model binding with soft deleted data

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'column_name' in Laravel

How to KeyBy where multiple items have the same key

Composer Curl error 60: SSL certificate problem: unable to get local issuer certificate

CodeIgniter extend CI_URI undefined method

Trying to iterate over a mongodb cursor twice - failing

Load a .env file with PHP

phpunit - testing is painfully slow

Woocommerce Edit Message "An account is already registered with your email address. Please log in."

Laravel Command Schedule Not Working Properly

Utf8 encoding issue with Laravel

How to access a var with "-" in PHP [duplicate]

PHP 8.1: strftime() is deprecated

About Contact Privacy policy Terms and conditions