Search
 
SCRIPT & CODE EXAMPLE
 

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';
        });
    }
}
Comment

laravel model custom factory

 // If you factory is out of standard, you can set an specifc
    // On your model, create a static method named newFactory

    protected static function newFactory()
    {
        return DatabaseFactoriesMyModelFactory::new();
    }

    //On your factory, add this
    protected $model = AppModelsMyModel::class;
Comment

PREVIOUS NEXT
Code Example
Php :: route() and with() in laravel 
Php :: array push in php 
Php :: wordpress use jquery in plugin 
Php :: laravel collection search 
Php :: continue in php 
Php :: laravel make factory 
Php :: html in php function 
Php :: json encode php 
Php :: explode return empty array 
Php :: php variable as javascript function parameter in echo 
Php :: Remove .php extension & Remove trailing slash 
Php :: signup form in php 
Php :: php array serialize 
Php :: How do I get a YouTube video thumbnail from the YouTube API? 
Php :: array_merge in php 
Php :: how to redirect to another page in php automatic after 2 second 
Php :: php insert to mysql 
Php :: Hide Add to cart button on specific products 
Php :: saving an image from pc to php 
Php :: remove invalid characters from a string laravel 
Php :: signup api in laravel 
Php :: laravel pdf export 
Php :: php base convert 
Php :: php session array 
Php :: ::latest() 
Php :: make resource in laravel 
Php :: remove space and line from json in php 
Php :: post format wordpress 
Php :: deprecation notice on phpmyadmin localhost | phpmyadmin deprecation notice 
Php :: laravel one to many relationship example 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =