actually a much easier way to get a readable array of what you (probably) want to see, is instead of using
dd($users);
or
dd(User::all());
use this
dd($users->toArray());
or
dd(User::all()->toArray());
which is a lot nicer to debug with.
EDIT - additional, this also works nicely in your views / templates so if you pass the get all users to your template, you can then dump it into your blade template
{{ dd($users->toArray()) }}
For everyone still searching for a nice way to achieve this, the recommended way is the dump()
function from symfony/var-dumper
.
It is added to documentation since version 5.2: https://laravel.com/docs/5.2/helpers#method-dd
Maybe try kint: composer require raveren/kint "dev-master" More information: Why is my debug data unformatted?
I have added a helper da()
to Laravel which in fact works as an alias for dd($object->toArray())
Here is the Gist: https://gist.github.com/TommyZG/0505eb331f240a6324b0527bc588769c
You can use var_dump
or print_r
functions on Blade themplate via Controller functions :
class myController{
public function showView(){
return view('myView',["myController"=>$this]);
}
public function myprint($obj){
echo "<pre>";
print_r($obj);
echo "</pre>";
}
}
And use your blade themplate :
$myController->myprint($users);
You can use this code on view.blade. {{var_dump($animales)}}
as suggested, you can use 'die and dump' such as
dd($var)
or only 'dump', without dying,
dump($var)
Source: Stackoverflow.com