• 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

Laravel-fopen: failed to open stream: Permission denied

Check if user online laravel

selected value from the listbox in php

PHP Fatal error: Class not found - PHPUnit

PHP to search within txt file and echo the whole line

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

Laravel Model save() & update() Not Saving

OctoberCMS / Anonymous Global Scope

How to KeyBy where multiple items have the same key

How to connect to MSSQL Server with PHP from Ubuntu 18.04?

Destroy session upon refresh

How to convert a carbon into string, to take the date only?

Error Class "LaravelFortifyFeatures" not found

PHP Sorting - getting 10, 11, 12 ... 1, 20, 2 rather than 1, 10, 11, 12 ... 2, 20

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP

About Contact Privacy policy Terms and conditions