Skip to main content
MyDiary’s friend system lets you connect with other users to share diary entries privately. The system uses a request-based model where connections must be mutually agreed upon.

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.
1

Navigate to Friends page

Click “Friends” or the friends icon in your navigation menu.
2

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
3

Search for specific users

Use the search bar to find users by:
  • Name (partial matches work)
  • Email address

User list filters

Shows all users except:
  • Yourself
  • Current friends (already connected)
These are users you can send friend requests to.

Sending friend requests

Connect with other users by sending them friend requests.
1

Find the user

Search for or browse to find the user you want to connect with.
2

Send request

Click the “Add Friend” or ”+” button next to their name.
3

Request sent

The request is created with:
  • Status: “pending”
  • Send timestamp: Current date/time
  • Sender: Your user ID
  • Recipient: Their user ID
You’ll see a “friend_request_send” confirmation message.
4

Wait for response

The recipient will see your request in their “Pending Requests” list and can accept or reject it.
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.
1

View pending requests

Navigate to Friends → Pending Requests (or filter to type=2).
2

Review the request

You’ll see:
  • The sender’s name
  • When the request was sent
  • Accept and Reject buttons
3

Accept the request

Click “Accept” or the checkmark button to become friends.
4

Friendship established

The request is updated:
  • Status changes from “pending” to “accepted”
  • Response timestamp is recorded
  • Both users are now friends
You can now share diary entries with each other.

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.
1

Find the request

Go to your Pending Requests list.
2

Reject

Click “Reject” or the “X” button next to the request.
3

Request removed

The friend request is permanently deleted from the database. The sender can send a new request in the future if desired.You’ll see a “friend_request_rejected” message.
Rejecting a request is permanent for that specific request. The user won’t be notified, but they may notice if they check their sent requests.

Managing friendships

Control your existing friend connections.

Removing friends

You can unfriend someone at any time:
1

Go to My Friends

Navigate to your friends list (type=1).
2

Find the friend

Locate the friend you want to remove.
3

Click remove

Click the “Remove Friend” or unfriend button.
4

Friendship ended

The friendship record is deleted:
  • You’re no longer friends
  • They can no longer see entries shared with “friends only”
  • Either of you can send a new friend request in the future

Friend request states

A request you sent is waiting for the recipient to accept or reject. You can cancel it before they respond.
Both users are now friends. You can share diary entries, view each other’s shared content, and like each other’s posts.
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:
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

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.
Check your pending requests regularly and respond to them. This helps other users know if you’re interested in connecting.
If you no longer want to share with someone, remove them from your friends list. This ensures your privacy settings remain meaningful.
If you know someone’s name or email, use the search feature to find them quickly instead of scrolling through all users.
The friend system is implemented in FriendRequestsController.php and the User model with the following features:
  • Database Structure: friend_requests table with sender_id, recived_id, status (pending/accepted), send_at, and response_at timestamps
  • Bidirectional Relations: User model defines friendsS() (sent requests) and friendsR() (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 type controls list display: blank=all users, 1=friends, 2=pending requests

Build docs developers (and LLMs) love