Laravel

How to Pass Value from Model to all the views in Laravel ? with video

It is a bit tricky to pass all the values to the view from the model in laravel.

First of all, make controllers and model is a must. I believe you have already done this

In controller:

View::composer('*', function($views){
$views->with('settings', App\Setting::all());
});

 

In Views: (according to my video)

@foreach($settings as $setting)
@if($setting->facebook!=null)
<a class="iconfont-wrapper" href="{{$setting->facebook}}" target="_blank">
<span class="p-2 mbr-iconfont socicon-facebook socicon"></span>
</a>
@endif
@if($setting->twitter!=null)
<a class="iconfont-wrapper" href="{{$setting->twitter}}" target="_blank">
<span class="p-2 mbr-iconfont socicon-twitter socicon"></span>
</a>
@endif
@endforeach

Video:

jaminrai

Share
Published by
jaminrai

Recent Posts

The Duck and the Tortoise: A Tale of Patience and Teamwork

In a serene forest by the edge of a sparkling lake, there lived a cheerful…

2 weeks ago

10 Smart Strategies for a Secure and Enjoyable Retirement

Retiring comfortably is a goal many aspire to achieve, and with the right strategies, it’s…

2 weeks ago

Troubleshooting a Slow Computer

Is your computer running frustratingly slow? Don't worry; you're not alone in facing this common…

2 weeks ago

The Clever Fox and the Greedy Crow

Once, in a sunny forest, Fox and Crow were friends. One day, Crow found a…

2 weeks ago

The Little Lantern and the Lost Stars

Once upon a time, in a cozy village nestled between rolling hills and whispering forests,…

2 weeks ago