Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

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

Laravel 5.6 Share Variable With Display Data in View

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

Today, We want to share with you Laravel 5.6 Share Variable With Display Data in View.In this post we will show you Laravel 5.6 Passing Variables from the Controller to View, hear for Laravel 5.6 share a variable to all views we will give you demo and example for implement.In this post, we will learn about Laravel 5.6 – Sharing $user variable in all views with an example.

Laravel 5.6 Share Variable With Display Data in View

Contents

  • Laravel 5.6 Share Variable With Display Data in View
    • 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 👉   how to integrate stripe payment gateway in php?

There are the Following The simple About Laravel 5.6 Share Variable With Display Data in View Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to share Variable with all Views in Laravel?, so the some major files How to share Variables to all views and pages for this example is following below.

  • View Files Laravel 5.6
  • services AppServiceProvider

Step 1 : Laravel View Files

resources/views/home.blade.php

@extends(‘layouts.layout’)

@section(‘content’)
   <h1>share a variable to all views using Laravel 5.6 Example</h1>
<b>Dashboard</b>
{{ Auth::user()->name }}, You are logged in! {{$activetickets}}
@endsection

Step 2 : Include Providers

app/Providers/AppServiceProvider.php

get()->count();
View::share(‘activetickets’, $tickets);
}

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

Laravel 5.6 – Sharing variable in all views

Simple Example of the Laravel 5.6 Share Variable With Display Data in View

Also Read This 👉   PHP Sending Mail Contact Form with jQuery AJAX

Step 1: Create Route

routes/web.php

Route::get(‘member’, function () {
return view(‘member’);
});

Route::get(‘user’, function () {
return view(‘user’);
});

Step 2 : Create Blade View

resources/views/member.blade.php

Simple create a two Laravel blade file Like as.

# resources/views/member.blade.php

<html>
  <body>
    <h1>Member Page</h1>
    <p><?= $companyname ?></p>
  </body>
</html>

resources/views/user.blade.php

# resources/views/user.blade.php

<html>
  <body>
    <h1>User Page</h1>
    <p><?= $companyname ?></p>
  </body>
</html>

Step 3: Share Variables

app/Providers/AppServiceProvider.php

# app/Providers/AppServiceProvider.php

public function boot()
{
// laravel 5.6 pass data to view from controller
view()->share(‘companyname’, ‘This is Pakainfo share data’);
}

Angular 6 CRUD Operations Application Tutorials

Read :

  • Technology
  • Google Adsense
  • Programming

Summary

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

Also Read This 👉   Passing data to views from routes in Laravel

I hope you get an idea about Sharing data between views in Laravel 5.6 Example.
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. laravel Views share Variable multiple to controller
  2. Laravel 5.8 Global Blade view variable
  3. How to pass data to all views in Laravel 5.8?
  4. Laravel 6 display flash message on view
  5. global variable for all controller and views in Laravel
  6. Global variable in laravel controller Example
  7. How to Check Whether a Variable is Set or Not in laravel blade?
create view in laravel 5 commandHow to share Variable with all Views in Laravel?Laravel 5.6 – Sharing variable in all viewslaravel display data in viewlaravel global variablelaravel pass data to view from controllerlaravel share data to some viewslaravel share variablelaravel view composer tutoriallaravel view share undefined variableSharing Data Between Views Using Laravel View ComposersView Composer to pass variable to all views

Post navigation

Previous Post:Password Protecting Website running on NGinx serve PHP-FPM
Next Post:PHP Laravel 5.7 Image Upload with Validation Tutorial Example

Advertise With Us

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

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 (166) Software (88) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (141) Technology (2392) Tips and Tricks (119) Tools (203) Top10 (477) Trading (89) Trending (71) VueJs (250) Web Technology (104) webtools (191) wordpress (166) World (322)

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