Skip to content
  • Home
  • Blog
    • yttags
    • Youtube
  • Categories
  • Tools
  • Server-Side
    • php
    • Node.js
    • ASP.NET
    • Magento
    • Codeigniter
    • Laravel
    • Yii
  • JS
    • AngularJS
    • Ajax
    • VueJs
    • jQuery
    • ReactJS
    • JavaScript
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us
Pakainfo

Pakainfo

Web Development & Good Online education

Laravel Global variable Sharing Data with all views

September 22, 2018 Pakainfo Technology, Laravel, Mysql, Mysqli, php, Programming Leave a comment
Rate this post

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
Read Also:  laravel Views share Variable multiple to controller

Step 1 : Laravel View Files

resources/views/home.blade.php

@extends('layouts.layout')

@section('content')
<h3>sharing data with all views laravel</h3>
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">Dashboard</div>

                <div class="panel-body">
                    {{ Auth::team()->name }}, You are logged in! {{$currentmembers}}
                </div>
            </div>
        </div>
    </div>
@endsection

Step 2 : Include Providers

app/Providers/AppServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use DB;
use \Illuminate\Support\Facades\View;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $members = DB::table('members')->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');
});

Free Live Chat for Any Issue

Step 2 : Create Blade View

resources/views/home.blade.php

<html>
  <body>
    <h1>Home Page</h1>
    <p><?= $teamname ?></p>
  </body>
</html>

resources/views/team.blade.php

<html>
  <body>
    <h1>Team Page</h1>
    <p><?= $teamname ?></p>
  </body>
</html>

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 :

  • Technology
  • Google Adsense
  • Programming
Read Also:  Global Config variable In Laravel 6 Example

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Download

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.

Related posts:

  1. global variable for all controller and views in Laravel
  2. Laravel 5.6 Share Variable With Display Data in View
  3. Laravel set global Variable in middleware, all controller and views
  4. laravel Views share Variable multiple to controller
  5. Laravel 5.8 Global Blade view variable
  6. laravel 5.8 global constants variable
  7. PHP Laravel 6 Global Variable Example
  8. Global variable in laravel controller Example
  9. How to Declare Global Variable in Laravel 6?
  10. Global Config variable In Laravel 6 Example
Read Also:  How To Pass Data To Views from controller In Laravel?
How to share Variable with all Views in Laravel?Laravel 5.3 - Sharing $user variable in all viewsLaravel 5.6 – Sharing variable in all viewslaravel global variablelaravel middleware pass variable to viewlaravel share variable with all controllerslaravel view share multiplelaravel view share not workinglaravel view share undefined variableshare a variable to all viewsSharing Data Between Views Using Laravel View ComposersSharing Data With All Viewssharing data with all views laravelview share laravel 5

Post navigation

Previous Post:Laravel Dependent Dropdown Example Tutorial From Scratch
Next Post:Angular 6 Form Validation Example Tutorial

Search

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me
Cricday

Categories

3movierulz (48) Ajax (464) AngularJS (377) ASP.NET (61) Bollywood (92) Codeigniter (174) CSS (96) Earn Money (61) Education (53) Entertainment (108) fullform (77) Google Adsense (62) Highcharts (77) Hollywood (93) JavaScript (1354) Jobs (39) jQuery (1421) Laravel (1083) LifeStyle (50) movierulz4 (47) Mysql (1029) Mysqli (890) Node.js (38) php (2110) Programming (2320) Python (96) ReactJS (37) Software (101) Software (77) Stories (78) tamilrockers (88) Tamilrockers kannada (48) Tamilrockers telugu (47) Tech (101) Technology (2359) Tips and Tricks (107) Tools (110) Top10 (291) Trading (49) Trending (45) VueJs (250) Web Technology (83) webtools (128) wordpress (165) World (118)

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here

Web Development & Good Online education : Pakainfo by Pakainfo.
Top
Subscribe On YouTube : Download Source Code & New itsolutionstuck
We accept paid guest Posting on our Site : Guest Post Chat with Us On WhatsApp