dimanche 26 juin 2016

Laravel Modelfactory - undefined offset

I have done some research on my problem and I end up finding way to general information about the issue I am facing. I have a model for a game where one flips a coin and wins baed on a heads-or-tails event. i am trying to use the model factory and generate some fake games for testing purposes. (i plan on using AJAX and view, which I am still learning about to achieve this effect).

When I SSH into homestead and run factory('App\Game', 10)->create(); in artisan tinker, I get an undefined offset noticed, and the dummy values are not produced or stored in the database.

Here is my code. Any assistance is greatly appreciated.

<?php

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/

$factory->define(App\Games::class, function (Faker\Generator $faker) {

    $players = ['player1_id' => rand(0,99), 'player2_id' => rand(0, 100)];
    $winner = rand(0, count($players) - 1);
    return [
        'id' => rand(1,100),
        'player1_id' => $players[0],
        'player2_id' => $players[1],
    ]

        'winner_id' => $players[$winner])

    ];
});



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/28UFHfX
via IFTTT

Aucun commentaire:

Enregistrer un commentaire