• 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

Wordpress wpdb->delete issue

Using array_intersect on a multi-dimensional array

Updating and Synchronizing Woocommerce Subscriptions to Custom Date

Laravel: HTML in notification

Utf8 encoding issue with Laravel

Login if user is active using Laravel Breeze

laravel automatically deletes server.php on php artisan serve

"Unable to load dynamic library 'pdo_sqlsrv.so' "Cenos7 PHP7.2.10

Google Gmail API - How to login programatically?

Get sql.h error on MacOS 12 (Monterey) sqsrv and pdo_sqsrv drive installation

phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO)

Pass a select with mysqli_fetch_row to a table

Laravel post contact form giving me error 419

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

Laravel set default language not working

About Contact Privacy policy Terms and conditions