Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us

Laravel Global variable Sharing Data with all views

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

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

Contents

  • Laravel Global variable Sharing Data with all views
    • Step 1 Laravel View Files
    • Step 2 Include Providers
  • Laravel 5.6 – Sharing variable in all views
    • Step 1 Create Route
    • Step 2 Create Blade View
    • Step 3 Share Variables
    • Read
    • Summary
    • Related posts
Also Read This πŸ‘‰   Bootstrap Daterangepicker Example

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')
<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');
});

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
Also Read This πŸ‘‰   Multidimensional arrays in Laravel

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.

Related posts:

  1. global variable for all controller and views in Laravel
  2. Laravel set global Variable in middleware, all controller and views
  3. laravel Views share Variable multiple to controller
  4. Laravel 5.8 Global Blade view variable
  5. laravel 5.8 global constants variable
  6. PHP Laravel 6 Global Variable Example
  7. Global variable in laravel controller Example
  8. How to Declare Global Variable in Laravel 6?
  9. Global Config variable In Laravel 6 Example
Also Read This πŸ‘‰   laravel Views share Variable multiple to controller
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

Advertise With Us

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

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

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (69) Education (61) Entertainment (130) fullform (86) Google Adsense (63) Highcharts (77) History (40) Hollywood (109) JavaScript (1357) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1029) Mysqli (890) php (2121) Programming (2332) Python (97) Software (167) Software (88) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (142) Technology (2392) Tips and Tricks (119) Tools (204) Top10 (482) Trading (91) Trending (71) VueJs (250) Web Technology (105) webtools (191) wordpress (166) World (323)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

Β© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites