When my new app, gets to this line:
$user_game = ( $user->games->count() == 0 ) ? $this->start( $game, $user ) : $user->pivot->data;
I get the following error:
ErrorException (E_NOTICE)
Trying to get property of non-object
It looks like $user->pivot->data
is not a property in my pivot table.
In my User class I have:
public function games(){
return $this->belongsToMany( Game::class )
->withPivot( [ 'data', 'finished' ] );
}
In my Game class I have:
public function users(){
return $this->belongsToMany( User::class )
->withPivot( [ 'data', 'finished' ] );
}
Attach method is working perfect, detach mode works too.
Am I missing something? For me it looks like it was done exactly as I should.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2I47WeY
via IFTTT
Aucun commentaire:
Enregistrer un commentaire