How to return variables in all views in laravel?

0

I have a laravel project, I have the index.blade.php that in that part of the header and footer are fixed, and content and that changes. My problem and return data from a controller to the footer, it lists me the data when I am on the homepage when I mute url gives me an undefined variable error which are the variables I have in the footer.

Route

Route::get('/', 'ListaDadosHomeController@lista_dados_home');

Controller

public function lista_dados_home (){

    $builder = DB::table('categorias')
            ->select('*')
            ->where('activo', '=', '1');

    $categorias_home = $builder->get();

    // LISTA FOODIES HOME

    $opinioes = DB::raw('(SELECT COUNT(*) AS id FROM posts WHERE user_id = users_social.id) as count_opinioes');

    $seguidores = DB::raw('(SELECT COUNT(*) AS followed FROM seguidores WHERE followed = users_social.id) as 'count_seguidores'');

    $builder = DB::table('users_social')
            ->select('*', $opinioes, $seguidores)
            ->where('activo', '=', '1');

    $top_foodies = $builder->limit(12)->get();

    // CONTA NUMERO DE ESTABELECIMENTOS

    $restaurantes = DB::table('estabelecimentos')->where('categoria', '=', 'restauracao')->count();
    $cafes = DB::table('estabelecimentos')->where('categoria', '=', 'bares')->count();
    $hoteis = DB::table('estabelecimentos')->where('categoria', '=', 'hotelaria')->count();
    $opinioes = DB::table('posts')->count();

    return view('home', ['top_foodies' => $top_foodies], ['categorias_home' => $categorias_home])->with('restaurantes', $restaurantes)->with('cafes', $cafes)->with('hoteis', $hoteis)->with('opinioes', $opinioes);

    return view('index')->with('restaurantes', $restaurantes)->with('cafes', $cafes)->with('hoteis', $hoteis)->with('opinioes', $opinioes);

} 
    
asked by anonymous 25.05.2017 / 20:46

0 answers