laravel 4 - Re-use the static method called in Blade template -


let's have static method called message::countnew() , method used count new message database.

and then, want display number of new messages in 1 page twice.

<!-- on top menu --> <nav>{{ message::countnew }} new message(s)</nav>  <!-- on other location of page (still on same page) --> <div>you have {{ message::countnew }} message(s) 

if that, laravel call static method (message::countnew()) twice? or have sort of mechanism maybe second call fetch value kind of cache.

or there best practice case?

thanks!

yes, execute query twice. executing query not duty of view layer.

you should execute queries in controller or in view composer.

there's handy tool trace how laravel app works.

https://github.com/barryvdh/laravel-debugbar


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -