jzonta / FakerRestaurant

Food and Beverage names generate using fakerphp/faker
MIT License
90 stars 38 forks source link

Add provider at laravel 8 #33

Closed amimaro closed 4 years ago

amimaro commented 4 years ago

Hi!

I am updating my Laravel project to version 8 and the model factory has changed a bit.

I tried with the code bellow with no success.

public function definition()
    {
        $this->faker->addProvider(new \FakerRestaurant\Provider\en_US\Restaurant($this->faker));
        return [
            'name' => $this->faker->fruitName(),
            'quantity' => $this->faker->randomFloat(null, 0, 100),
            'price' => $this->faker->randomFloat(null, 0, 100),
        ];
    }
jzonta commented 4 years ago

Hello, send your error message for i can help you.

I create a new laravel8 project, in my www/database/factories/UserFactory.php

<?php

namespace Database\Factories;

use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class UserFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = User::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        $this->faker->addProvider(new \FakerRestaurant\Provider\en_US\Restaurant($this->faker));
        return [
            'name' => $this->faker->foodName(),
            'email' => $this->faker->unique()->safeEmail,
            'email_verified_at' => now(),
            'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
            'remember_token' => Str::random(10),
        ];
    }
}

I run the command "php artisan db:seed"

Everything working In my project

Don't forget to run "composer require jzonta/faker-restaurant"

amimaro commented 4 years ago

It looks like it's working here now. Thank you! I will close this issue.