A
A
Artyom2019-06-08 22:48:56
Laravel
Artyom, 2019-06-08 22:48:56

How to pass a variable to all View laravel at once?

How to pass the variable I need so that it is available in all views?
Now I transfer only through the controllers of each view separately, and I over immediately in all so that it can be seen.
return view('home')->with('role',$role);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jazzus, 2019-06-08
@jazzus

View Composers
AppServiceProvider
But judging by the name of the variable, you don't need to pass anything to the templates, but use the can directive

P
prostoprofan, 2019-06-08
@prostoprofan

You can make a global array like
$view_data = [];
$this->view_data['var_1'] = $data;
return view('view_file', $this->view_data);
Use this construction everywhere and get an array with data at the output and process them on the view

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question