mwal mwal - 2 months ago 9
PHP Question

Laravel View::composer()

What is the right circumstance to use these?

If I have a view partial which always needs the same data (say to fill out some nav links) and I provide that data in a view composer, do I need to worry about cases where the main page also needs, and loads, this data?

i.e. is it possible to end up calling for the same data twice?

Answer

short answer is yes, you might call for the same data twice.

try adding

DB::enableQueryLog();

before any database calls, and in the end, before the view is returned, do this:

var_dump(DB::getQueryLog());

Then you can see if you are calling the same data twice, in the query log.