Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aboutsam's avatar

Check if Friendship Request was send

I try to create a Friendship Request function. I had a button in my output.blade.php which placed into a @foreach loop.

this loop shows every user which is not my friend.

when i click on the "send friend request" button, i will that the button completely changed. i saw a tutorial on youtube where they put the php code directly in the blade file that check in every loop the DB if the values already exist in the friendship table.

I'm not able to call the DB because i get a protection exception.

i think the solution will be vue.js, but i never work with them. so my question:

how to check on the fly a table row in the database after i insert the value in my DB?

i had 3 tables:

  1. users id | email ...

  2. friends id | users_id | friends_id ...

  3. friendsrequest id | requester_id | friend_id ...

when someone click on the "send friend request" button i create a record in friendsrequest

friendsrequest id: 69 requester_id: 9 friend_id: 12

how can i change the layout of the button after insert the friendsrequest record? or of all friendsrequest records that i send?

0 likes
2 replies
martinbean's avatar

i saw a tutorial on youtube where they put the php code directly in the blade file that check in every loop the DB if the values already exist in the friendship table.

@aboutsam I don’t know what tutorial you’re watching, but it sounds bad. You shouldn’t have logic in a Blade template, and you definitely shouldn’t be performing queries in a loop (see N+1 problem).

Please or to participate in this conversation.