Laravel, show static content

1

I am trying to always show the same content in the footer (Content that is stored in a field of the data base). The footer has to appear in all the pages of the web.

The problem is not how to pose it:

$footer = DB::select('SELECT * FROM generos');
return view('home', ['footer' => $footer]);

Pass variable $footer to all view that contains footer?

Is there no way to create the variable $ footer in a single site and be able to pass it to all the views?

    
asked by Shaz 30.07.2017 в 01:07
source

1 answer

1

The method that Laravel proposes is to do it with View::share() in the AppServiceProvider:

<?php

namespace App\Providers;

use Illuminate\Support\Facades\[DB, View];

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $footer = DB::select('SELECT * FROM generos');
        View::share('footer', $footer);
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

More information in the documentation: link

    
answered by 30.07.2017 / 01:14
source