Today, We want to share with you How to pass data to all views in Laravel 5.8?.In this post we will show you share a variable to all views, hear for Share a variable across views in Laravel (Example) we will give you demo and example for implement.In this post, we will learn about How to share Variable with all Views in Laravel? with an example.
How to pass data to all views in Laravel 5.8?
There are the Following The simple About How to pass data to all views in Laravel 5.8? Full Information With Example and source code.
As I will cover this Post with live Working example to develop How to pass data to all views in Laravel 5.8?, so the View Composer to pass variable to all views for this example is following below.
Step 1: Create Route
Lets us first of all we can create two fresh laravel 5.8 routes:
Step 2: routes/web.php
... Route::get('product', function () { return view('product'); }); Route::get('member', function () { return view('member'); });
Step 3: Create Laravel Blade View
and then, we can simple make two fresh views:
Step 4: resources/views/product.blade.php
Admin Page
= $welcome-msg ?>
Step 5: resources/views/member.blade.php
Member Page
= $welcome-msg ?>
Step 6: Share Variables
We have simple understanding laravel structure flow enough regarding the above step by step simple process so let us now start simple putting shared data in onther place. To do so, include a following Laravel code in app/Providers/AppServiceProvider:
Step 7: app/Providers/AppServiceProvider.php
public function boot() { // add this view()->share('welcome-msg', 'Welcome to pakainfo.com'); }
Step 8: Testing
and last step, We just added a simple key-value pair to share in all our laravel blade views files. af thatter we can test this with:
localhost:8000/product
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about How to pass data to all views in Laravel 5.8?.
I would like to have feedback on my infinityknow.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.