Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Faker Unknown formatter

Tags:

php

laravel

faker

I have tried everything possible but I could not get to the bottom of what I am doing wrong. I am trying to load my database with dummy data but I keep get unknown formatter "description". Description is one of the variables I am using.

Below is my factory code and my seeder coder

use Faker\Generator as Faker;
use Analytics\Blockgrant;

$factory->define(Blockgrant::class, function (Faker $faker) {
    return [
        'description' => $faker->description,
        'value' => $faker->value
    ];
});

<?php

use Faker\Generator as Faker;
use Universityobfanalytics\Blockgrantcomponents;

$factory->define(Blockgrantcomponents::class, function (Faker $faker) {
    return [
        'blockgrants_id' => $faker->blockgrants_id,
        'description' => $faker->description,
        'percentage' => $faker->percentage,
        'value' => $faker->value
    ];
});

<?php

use Illuminate\Database\Seeder;
use Analytics\Blockgrant;
use Analytics\Blockgrantcomponents;

class BlockgrantSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        factory(Blockgrant::class, 10)->create()->each(function ($blockgrant) {
            $blockgrant->blockgrantcomponents()->save(factory(Blockgrantcomponents::class)->create());

        });
    }
}

I am using a one to one hasOne and belongsTo relationship

Can somebody please assist by telling me what I am doing wrong.

like image 905
olammy Avatar asked Nov 29 '19 05:11

olammy


2 Answers

It can be because you are using PHPUnit\Framework\TestCase instead of Tests\TestCase in your test.

like image 50
Victor Timoftii Avatar answered Sep 29 '22 19:09

Victor Timoftii


The faker library does not have the properties you are trying to access.

You can only make use of formatters like:

$faker->name
$faker->text
$faker->paragraphs() 
$faker->sentences() 

It would be best you go through the faker documentation to check the full list of available formatters here

like image 34
thefabdev Avatar answered Sep 29 '22 21:09

thefabdev