mardi 30 mai 2017

Laravel 5 Call to a member function createPlayer() on integer

I have a store procedure that creates a team for the logged in user like this:

public function store(Request $request)
{
    /**
     * Create Team
     */
    $this->validate($request, [
        'name' => 'required|min:3|max:255',
    ]);

    $team = Auth::user()->createTeam($request);

    /**
     * Create players
     */
    $players = [
        1   => 'ARQ',
        2   => 'DEF',
        3   => 'DEF',
        4   => 'DEF',
        5   => 'DEF',
        6   => 'MED',
        7   => 'MED',
        8   => 'MED',
        9   => 'ATA',
        10  => 'MED',
        11  => 'ATA',
        12  => 'ARQ',
        13  => 'DEF',
        14  => 'DEF',
        15  => 'MED',
        16  => 'MED',
        17  => 'MED',
        18  => 'ATA',
        19  => 'DEF',
        20  => 'ARQ',
        21  => 'DEF',
    ];

    foreach ($players as $num => $pos) {
        $player = $team->createPlayer($num, $pos);
    }

    $team->save();

    return redirect()->route('strategy');
}

and this works fine most of the time, but there are some times that it throws a Call to a member function createPlayer() on integer and can't replicate it, but the most weird part is that even when throwing the error the team and the players are created normally into the database. After refreshing the page everything continues as expected.

So, why could this error be appearing even when everything is working normally? How could the $team instance be getting changed into an integer?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire