Laravel 调试:更好的 Debug 函数 dd => dda
dd
函数用来看变量类型很有帮助,但是有时候我们要查看 Eloquent 数据时,输出是这样的:
Book {#399 ▼
#fillable: array:10 [▶]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:13 [▶]
#original: array:13 [▶]
#relations: []
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [▶]
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
+exists: true
+wasRecentlyCreated: false
}
使用以下函数 dda
:
function dda($model)
{
if (method_exists($model, 'toArray')) {
dd($model->toArray());
} else {
dd($model);
}
}
就能得到我们想要的:
array:13 [▼
"id" => 1
"name" => "name"
"user_id" => 1
"created_at" => "2017-04-18 06:48:42"
"updated_at" => "2017-04-18 06:48:42"
]
dda
等于: dd to array
推荐文章: