To prevent a user from following themselves, you can add a check in your code before creating a new follow_system record. Here's an example of how you can do it:
// Assuming you have a FollowSystem model
public function store(Request $request)
{
$followerId = $request->input('follower_id');
$followingId = $request->input('following_id');
// Check if the follower and following IDs are the same
if ($followerId === $followingId) {
return response()->json(['error' => 'You cannot follow yourself'], 400);
}
// Create the follow_system record
$followSystem = new FollowSystem;
$followSystem->follower_id = $followerId;
$followSystem->following_id = $followingId;
$followSystem->followed_at = now();
$followSystem->save();
return response()->json(['message' => 'Followed successfully'], 200);
}
In this example, we first check if the follower_id and following_id are the same. If they are, we return an error response indicating that the user cannot follow themselves. Otherwise, we proceed with creating the follow_system record as usual.
Note: This is just an example implementation. You may need to modify it based on your specific application structure and requirements.