S
S
Shamil Khairulaev2021-06-09 17:58:18
Laravel
Shamil Khairulaev, 2021-06-09 17:58:18

How to check if a model is in a relationship with a specific model?

I have implemented a system of relations between subscribers and authors. I need to find out if a certain author is in the list of subscriptions of another user in order to display the "subscribe" or "unsubscribe" button

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2021-06-09
@ComPUCKter

$user->subscribers()
    ->where('id', $subscriberId)
    ->exists();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question