now users can be followed

This commit is contained in:
Ghostie 2024-08-23 13:54:04 -05:00
parent fdd0b1ed07
commit 31262f442c
4 changed files with 37 additions and 1 deletions

View File

@ -2,9 +2,15 @@
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class FollowerController extends Controller
{
//
public function store(User $user)
{
$user->followers()->attach(auth()->user()->id);
return back();
}
}

View File

@ -8,4 +8,9 @@ use Illuminate\Database\Eloquent\Model;
class Follower extends Model
{
use HasFactory;
protected $fillable = [
"user_id",
"follower_id"
];
}

View File

@ -55,4 +55,12 @@ class User extends Authenticatable
{
return $this->hasMany(Like::class);
}
// store the followers
public function followers()
{
return $this->belongsToMany(User::class, "followers", "user_id", "follower_id");
}
// store the following
}

View File

@ -44,6 +44,23 @@
{{ $user->posts->count() }}
<span class="font-normal">Posts</span>
</p>
@auth
@if ($user->id !== auth()->user()->id)
<form action="{{ route('users.follow', $user) }}" method="POST">
@csrf
<input type="submit"
class="bg-blue-600 text-white uppercase rounded-lg px-3 py-1 text-xs font-bold cursor-pointer"
value="follow">
</form>
<form action="#" method="POST">
@csrf
<input type="submit"
class="bg-red-600 text-white uppercase rounded-lg px-3 py-1 text-xs font-bold cursor-pointer"
value="unfollow">
</form>
@endif
@endauth
</div>
</div>