'How can I pass data into app.blade.php with Eloquent in Laravel 8

I am making navbar menu. I want to fetch data from database and display here. Now how can I do that ? Is it possible without using route?



Solution 1:[1]

Go to App/Providers/AppServiceProvider

  <?php

namespace App\Providers;
use Illuminate\Support\Facades\View;
use DB;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
       View::share('categories', DB::select('select * from categories')); 
    }
}

and you can get your datas

@foreach($categories as list)

<ul>
<li> {{$list->name}} </li>
<ul>

@endforeach

I hope it helps you! good luck!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kusursuz