samedi 25 mai 2019

Must be an instance of App, Relation, instance of Illuminate BelongsToMany returned

I've got one error when trying to attach a program in Laravel with belongsToMany Relationship. Someone that knows what I'm doing wrong?

Controller

$user = User::where('id', $request->input('user_id'))->first();
$program = Program::where('id', $request->input('program_id'))->first();
$update = $user->programs()->attach($program);

Relationship

public function programs() : Relation
{
    return $this->belongsToMany(\App\Program::class, 'program_user');
}

I've got this error --> "Return value of App\User::programs() must be an instance of App\Relation, instance of Illuminate\Database\Eloquent\Relations\BelongsToMany returned"



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2VR9s9U
via IFTTT

Aucun commentaire:

Enregistrer un commentaire