Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel factory in custom namespace

<?php

namespace AppProviders;

use IlluminateSupportServiceProvider;
use IlluminateDatabaseEloquentFactoriesFactory;
use IlluminateSupportStr;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
      	//Add THIS
        Factory::guessFactoryNamesUsing(function (string $model_name) {
            $namespace = 'DatabaseFactories';
            $model_name = Str::afterLast($model_name, '');
            return $namespace . $model_name . 'Factory';
        });
    }
}
 
PREVIOUS NEXT
Tagged: #laravel #factory #custom #namespace
ADD COMMENT
Topic
Name
4+4 =