How to display a readable array - Laravel
dd()
dumps the variable and ends the execution of the script (1), so surrounding it with <pre>
tags will leave it broken. Just use good ol' var_dump()
(or print_r()
if you know it's an array)
Route::get('/', function()
{
echo '<pre>';
var_dump(User::all());
echo '</pre>';
//exit; <--if you want
});
Update:
I think you could format down what's shown by having Laravel convert the model object to array:
Route::get('/', function()
{
echo '<pre>';
$user = User::where('person_id', '=', 1);
var_dump($user->toArray()); // <---- or toJson()
echo '</pre>';
//exit; <--if you want
});
(1) For the record, this is the implementation of dd():
function dd()
{
array_map(function($x) { var_dump($x); }, func_get_args()); die;
}
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()) }}