Today, We want to share with you Laravel Global variable Sharing Data with all views.In this post we will show you Laravel 5.7 – Sharing $user variable in all views, hear for How to share Variable with all Views in Laravel we will give you demo and example for implement.In this post, we will learn about Sharing Data Between Views Using Laravel View Composers with an example.
Laravel Global variable Sharing Data with all views
There are the Following The simple About Laravel Global variable Sharing Data with all views Full Information With Example and source code.
As I will cover this Post with live Working example to develop Sharing Data With All Views, so the How to share Variable with all Views in Laravel for this example is following below.
- view share laravel 5
- laravel global variable
- laravel view share multiple
- sharing data with all views laravel
Step 1 : Laravel View Files
resources/views/home.blade.php
@extends('layouts.layout') @section('content')sharing data with all views laravel
@endsectionDashboard{{ Auth::team()->name }}, You are logged in! {{$currentmembers}}
Step 2 : Include Providers
app/Providers/AppServiceProvider.php
get()->count(); View::share('currentmembers', $members); } /** * Register any application services. * Laravel Global variable Sharing Data with all views * @return void */ public function register() { // } }
Laravel 5.6 – Sharing variable in all views
Step 1: Create Route
routes/web.php
Route::get('home', function () { return view('home'); }); Route::get('team', function () { return view('team'); });
Step 2 : Create Blade View
resources/views/home.blade.php
Home Page
= $teamname ?>
resources/views/team.blade.php
Team Page
= $teamname ?>
Step 3: Share Variables
app/Providers/AppServiceProvider.php
# app/Providers/AppServiceProvider.php public function boot() { // add Your get varibles data this view()->share('teamname', 'Latest 2021 Players Teams'); }
Angular 6 CRUD Operations Application Tutorials
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Laravel Global variable Sharing Data with all views.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.