Answer the question
In order to leave comments, you need to log in
How to call a method once in Laravel?
Hello! Such situation. There is a message repository, it has a method for checking for new messages. The method is called in the parent layout. There was a need to call it on a specific page. Then, when this page is called, the method will be called twice. How can I get the result only 1 time and use it where I need? Thank you!
Answer the question
In order to leave comments, you need to log in
If you pull the method in the app service provider and save it to a variable, then through the view share you can share it into layout and view, and it will twitch once
https://laravel.com/docs/7.x/views#sharing-data-wi ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question