skip to Main Content

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


  1. You may use

    {{ dump($variable); }}
    

    OR

    @php dump($variable); @endphp
    

    Update

    List all registered variables inside a Laravel view

    {{ dump(get_defined_vars()['__data']) }}
    

    See reference

    Login or Signup to reply.
  2. 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 of IlluminateViewFactory (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.

    Login or Signup to reply.
  3. First you should pass variables from controller to view.Best way is to use compact in second argument of return view like this:

    return view("viewName",compact("variable1","variable2",...));
    

    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.But echo() is for release version.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search