M
M
Maxim Vlasov2020-07-23 23:23:46
Laravel
Maxim Vlasov, 2020-07-23 23:23:46

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

1 answer(s)
D
Daria Motorina, 2020-07-24
@tr0yka

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 question

Ask a Question

731 491 924 answers to any question