Pass all data to all pages laravel
snippet in php

Pass all data to all pages laravel

user3947

use Illuminate\Support\Facades\View;

class BaseController extends Controller
{
  public function __construct()
  {
    //its just a dummy data object.
    $user = User::all();

    // Sharing is caring
    View::share('user', $user);
  }
}

Pass all data to all pages laravel

user5936

namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

use Illuminate\Support\Facades\Auth;
use DB;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
         View::share('key', 'value');
         Schema::defaultStringLength(191);

        $categories=DB::table('categories')->get();
        View::share('categories',$categories);  

    }

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

Pass all data to all pages laravel

user2628

this work :)
use Illuminate\Support\Facades\View;

use varable on all site pages laravel

user7509

# app/Providers/AppServiceProvider.php

public function boot()
{
   // add this
    view()->share('someKey', 'This is shared data');
}

use varable on all site pages laravel

user4791

php artisan make:middleware SomeMiddleware

use varable on all site pages laravel

user4286

{{Session::get('website_name', 'Value Goes Here')}}