samedi 20 mars 2021

Laravel How do I insert a column in many to many relationship

could anyone help me. I'm making a follow system. My code is working but I want the integer value going into the follower column in users. Is a pivot appropriate to use or is there something else I could use? Here's my code:

user model  
public function followers()
{
    return $this->belongsToMany(User::class, 'followers', 'leader_id', 'follower_id');
}
public function followings()
{
    return $this->belongsToMany(User::class, 'followers', 'follower_id', 'leader_id');
}
follower model protected $fillable=[

     "follower_id",
     "leader_id",
     
     
    ];
Controller    public function followCount( int $id)
    {
        $user = User::find($id); 
         
    $user->followers()->attach(auth()->user()->id);
   

    return redirect()->back()->with('success', 'Successfully followed the user.');
     
    }
     ```



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3cTJsFd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire