public function follow_unfollow(Request $request)
{
$fields=$request->validate([
'followed_id'=>'required|exists:users,id'
]);
$follow=Follower::where([
'followed_id'=>$request->followed_id,
'follower_id'=>auth()->id(),
])->first();
$un_follow=Follower::where([
'followed_id'=>$request->followed_id,
'follower_id'=>auth()->id(),
'status'=>1,
])->first();
if($follow === null)
{
$auth_id=Follower::create([
'followed_id'=>$fields['followed_id'],
'follower_id'=>auth()->id(),
'status'=>1,
]);
return response()->json([
'message'=>'Your are followed Now',
'data'=>$auth_id,
],200);
}
else if($un_follow !==null)
{
$unfollow = $follow->update([
'followed_id' => $fields['followed_id'],
'follower_id'=>auth()->id(),
'status'=>0,
]);
return response()->json([
'message' => 'You have unfollowed Now',
'data' => $unfollow,
],200);
}
else
{
$data['product']=Product::where('vendor_id',$fields['followed_id'])->get();
$unfollow = $follow->update([
'followed_id' => $fields['followed_id'],
'follower_id'=>auth()->id(),
'status'=>1,
]);
return response()->json([
'message'=>'You have followed Now',
'products' => $data['product'],
'data'=>$unfollow,
],200);
}
}
0 Comments