• 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 5.5 change unauthenticated login redirect url

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

Filter WooCommerce products with post__in and additional meta queries

Unable to run composer install

How to unlink image from folder?

Exact alternate to mcrypt_encrypt in PHP 7.2

Undefined variable in Laravel 8 project (php 7.4)

ConstraintViolationListInterface to Exception in Symfony

How in Laravel run JavaScript code stored in php variable?

Make Shipping Method fields Mandatory on Woocommerce checkout page

How To Access A Column In M-M Relationship Table In Laravel

PHP/HTML: Creating A SubMenu

Best way to scrolldown onpageload

how to remove %20 in the url in php

Laravel 5 controller sending JSON integer as string

About Contact Privacy policy Terms and conditions