now users can be followed
This commit is contained in:
parent
fdd0b1ed07
commit
31262f442c
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -8,4 +8,9 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Follower extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
"user_id",
|
||||
"follower_id"
|
||||
];
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user