I’m fresh beginner in the PHP Framework Laravel (i’m using version 5.8), and i would like to dump all the variables of a controller from a view. Is that possible to do that ?
Thanks for your help 🙂
I’m fresh beginner in the PHP Framework Laravel (i’m using version 5.8), and i would like to dump all the variables of a controller from a view. Is that possible to do that ?
Thanks for your help 🙂
3
Answers
You may use
OR
Update
List all registered variables inside a Laravel view
See reference
Laravel internally uses a
$__data
array which contains all available variables (including variables shared with all views.In addition it contains an instance of
IlluminateFoundationApplication
(as$__data['app']
) and an instance ofIlluminateViewFactory
(as$_data['__env']
).You can filter these out with
IlluminateSupportArr::except($__data, ['app', '__env'])
.But you should not rely on this since it’s an internal variable which might change in a future update without any warning.
First you should pass variables from controller to view.Best way is to use
compact
in second argument of return view like this:Notice that in compact just use variable name without
$
sign.After pass variables to view you can use
{{dd($variable1)}}
or{{echo($variable1)}}
(e.g) in every where you like to see variables.dd()
do not allow to debug remaining codes and die program for show variable and it is better for debugging.Butecho()
is for release version.