Support the ongoing development of Laravel.io →
Views Blade
Last updated 2 years ago.
0

Is dificult for explain but i want to try. I have index.blade.php. In index.blade.php i have @include('header.blade.php') and @include('footer.blade.php'). The content inside index.blade.php is a list of users from bbdd. This is ok and work well. Now, in header.blade.php, I have a icon with alerts and show the last 5 alerts. But this header.blade.php is common content from all site but inside the alert box i need load the last alerts from table alerts of bbdd. How I could load inside alert box this content. I could create a function in basecontroller with this action, but ¿how could i call it in the template header.blade.php?

Last updated 2 years ago.
0

In your BaseController you can use this:

public function __construct () {
    $ alerts = Alert::where()->get(); // get alerts from database
    View::share ('alerts', $alerts);
}

Using share() will make that available in all views.

Last updated 2 years ago.
0

Thank you pickupman.

Last updated 2 years ago.
0

This didn't work for me... what am I missing??? :(

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

jariscano jariscano Joined 24 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.