lundi 2 décembre 2019

Can not Use Laravel Factory For Object Models

I have a Class Like This :

class Ip
{

    public $ip;

    /**
     * @return mixed
     */
    public function getIp()
    {
        return $this->ip;
    }

    /**
     * @param mixed $ip
     */
    public function setIp($ip)
    {
        $this->ip = $ip;
    }

}

and I Write a Factory For This :

/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(\Modules\FraudDetection\ObjectModels\Ip::class, function (Faker\Generator $faker) {

    return [
        'ip' => $faker->numerify('###.###.##.###')
    ];
});

But When i Want to Use That Factory , the result is null :

{"ip":null}

I know If I Extend Model It Will Work . Is There Any Other Solution To use Factory without extending model ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire