*/ protected $fillable = [ 'name', 'username', 'email', 'password', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } public function posts() { return $this->hasMany(Post::class); } public function likes() { return $this->hasMany(Like::class); } // store the followers public function followers() { return $this->belongsToMany(User::class, "followers", "user_id", "follower_id"); } // check if a user already follows another user public function following(User $user) { return $this->followers->contains($user->id); } // store the following }