What you are looking for is View Composers
On all page, i have a topmenu that needs to query the database... where should i place my Eloquent code
Hello to all, I'm creating a new website and i have a question about my top menu.... In my old website, i included a php page topmenu.php in my php template...... and in this top menu.... if user is logged, i query the database to check for new messages... or if not logged, i show register and login button..
But now... in Laravel... i create a template (main.blade.php) and i include my top menu And i created a view for a page... let's take contact us page.... i created contactus.blade.php and in this contactus.blade.php i extends to my main template : @extends('main')
But where should i query my database to check for new messages and other things ?
In middleware ?
I suppose that i cant put it in a specific controller because in EACH controller i will need to paste my code to query the database....
When user will navigate on my site... he/she can click to go on orders page, members page, profiles page, contact us page... so i suppose my code to query the database to check for new messages or notifications should not be paste on each controller.....
So where should i place this code ?
Thanks a lot !
Pascal
Please or to participate in this conversation.