How the friend system works
The friend system operates on a bidirectional relationship model:- Friend requests can be sent to any user
- Requests remain pending until the recipient responds
- Recipients can accept or reject requests
- Once accepted, both users become friends and can share entries
- Either friend can remove the friendship at any time
All friend relationships are mutual—if you’re friends with someone, they’re automatically friends with you. There are no one-way connections.
Finding users
Discover other MyDiary users to connect with.Browse available users
The page displays users based on your current filter:
- All Users: Everyone except yourself
- My Friends: Only users you’re connected with
- Pending Requests: Users who sent you friend requests
User list filters
- All users (default)
- My friends (type=1)
- Pending requests (type=2)
Shows all users except:
- Yourself
- Current friends (already connected)
Sending friend requests
Connect with other users by sending them friend requests.Request sent
The request is created with:
- Status: “pending”
- Send timestamp: Current date/time
- Sender: Your user ID
- Recipient: Their user ID
You can cancel a pending request you sent by clicking the button again. The request will be removed before they respond.
Accepting friend requests
Respond to friend requests you’ve received from other users.Review the request
You’ll see:
- The sender’s name
- When the request was sent
- Accept and Reject buttons
Smart acceptance
If you try to send a friend request to someone who already sent you a request, MyDiary automatically accepts their existing request instead of creating a duplicate. This creates an instant friendship.
Rejecting friend requests
Decline friend requests you don’t want to accept.Managing friendships
Control your existing friend connections.Removing friends
You can unfriend someone at any time:Friend request states
Pending state
Pending state
A request you sent is waiting for the recipient to accept or reject. You can cancel it before they respond.
Accepted state
Accepted state
Both users are now friends. You can share diary entries, view each other’s shared content, and like each other’s posts.
No relationship
No relationship
No friend request or friendship exists. Either user can send a friend request to initiate a connection.
Friend request behavior
The system handles various scenarios intelligently:- Duplicate prevention
- Mutual acceptance
- Request cancellation
- Unfriending
You cannot:
- Send a request to someone who already sent you one (it auto-accepts instead)
- Send multiple pending requests to the same user
- Send a request to someone who’s already your friend
Friend visibility in entries
Friends are integrated with the diary entry system:- When creating or editing an entry, you can select specific friends to share with
- Friends can only see entries you’ve explicitly shared with them
- If you unfriend someone, they immediately lose access to entries shared with them
- Your “My Friends” list shows only accepted friendships for sharing purposes
Privacy tip: Only users you’ve accepted as friends can be selected when sharing diary entries. Pending requests don’t grant entry access.
Best practices
Be selective with friend requests
Be selective with friend requests
Only connect with users you trust and want to share personal diary entries with. Your diary content is private and should only be shared with genuine friends.
Respond to requests promptly
Respond to requests promptly
Check your pending requests regularly and respond to them. This helps other users know if you’re interested in connecting.
Clean up your friends list
Clean up your friends list
If you no longer want to share with someone, remove them from your friends list. This ensures your privacy settings remain meaningful.
Use search effectively
Use search effectively
If you know someone’s name or email, use the search feature to find them quickly instead of scrolling through all users.
Technical implementation details
Technical implementation details
The friend system is implemented in
FriendRequestsController.php and the User model with the following features:- Database Structure:
friend_requeststable with sender_id, recived_id, status (pending/accepted), send_at, and response_at timestamps - Bidirectional Relations: User model defines
friendsS()(sent requests) andfriendsR()(received requests) using belongsToMany - Smart Request Handling:
friendRequest()method checks for existing requests, friendships, and auto-accepts reciprocal requests - Request States: Requests can be pending (awaiting response), accepted (active friendship), or non-existent (deleted/rejected)
- Cascade Deletion: When a user is deleted, all their friend requests and friendships are automatically cleaned up via foreign key constraints
- Search Functionality: Supports filtering by name and email using LIKE queries with wildcard matching
- Type Filtering: URL parameter
typecontrols list display: blank=all users, 1=friends, 2=pending requests