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"
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire