Laravel 辅助函数扩展 dd => dda

Laravel

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)
{
    dd($model->toArray());
}

就能得到我们想要的:

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

评论数量: 0

17
点赞
883
浏览
0
评论

贡献 538
Summer
Building Products Users Love