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
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’)share a variable to all views using Laravel 5.6 Example
Dashboard {{ 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
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.phpMember Page
= $companyname ?>
resources/views/user.blade.php
# resources/views/user.blade.phpUser Page
= $companyname ?>
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 :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
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.