如何在刀片Laravel中显示元键值

时间:2016-07-12 13:13:40

标签: php laravel laravel-5

任何人都可以告诉我如何在我看到输出的数组中显示元键值:

[0] => Resource Object
                (
                    [presenter:protected] => ResourcePresenter
                    [table:protected] => resources
                    [parentColumn:protected] => parent_id
                    [leftColumn:protected] => lft
                    [rightColumn:protected] => rgt
                    [depthColumn:protected] => depth
                    [guarded:protected] => Array
                        (
                            [0] => id
                            [1] => parent_id
                            [2] => lft
                            [3] => rgt
                            [4] => depth
                        )

                    [orderColumn:protected] => 
                    [scoped:protected] => Array
                        (
                        )

                    [connection:protected] => 
                    [primaryKey:protected] => id
                    [perPage:protected] => 15
                    [incrementing] => 1
                    [timestamps] => 1
                    [attributes:protected] => Array
                        (
                            [id] => 551
                            [parent_id] => 180
                            [lft] => 383
                            [rgt] => 384
                            [depth] => 1
                            [owner_id] => 41
                            [type] => 2
                            [title] => test
                            [act_name] => 551.jpg
                            [display_name] => test
                            [notes] => 
                            [size] => 3054
                            [is_archived] => 0
                            [created_by] => 41
                            [created_at] => 2016-07-12 07:30:54
                            [updated_by] => 41
                            [updated_at] => 2016-07-12 07:30:56
                            [created] => 2016-07-12 07:30:54
                            [updated] => 2016-07-12 07:30:54
                        )

                    [original:protected] => Array
                        (
                            [id] => 551
                            [parent_id] => 180
                            [lft] => 383
                            [rgt] => 384
                            [depth] => 1
                            [owner_id] => 41
                            [type] => 2
                            [title] => test
                            [act_name] => 551.jpg
                            [display_name] => test
                            [notes] => 
                            [size] => 3054
                            [is_archived] => 0
                            [created_by] => 41
                            [created_at] => 2016-07-12 07:30:54
                            [updated_by] => 41
                            [updated_at] => 2016-07-12 07:30:56
                            [created] => 2016-07-12 07:30:54
                            [updated] => 2016-07-12 07:30:54
                        )

                    [relations:protected] => Array
                        (
                            [resourceMeta] => Illuminate\Database\Eloquent\Collection Object
                                (
                                    [items:protected] => Array
                                        (
                                            [0] => ResourceMeta Object
                                                (
                                                    [table:protected] => resources_info
                                                    [timestamps] => 
                                                    [fillable:protected] => Array
                                                        (
                                                            [0] => resource_id
                                                            [1] => key
                                                            [2] => value
                                                        )

                                                    [connection:protected] => 
                                                    [primaryKey:protected] => id
                                                    [perPage:protected] => 15
                                                    [incrementing] => 1
                                                    [attributes:protected] => Array
                                                        (
                                                            [id] => 1924
                                                            [resource_id] => 551
                                                            [key] => doc_type
                                                            [value] => jpg
                                                        )

                                                    [original:protected] => Array
                                                        (
                                                            [id] => 1924
                                                            [resource_id] => 551
                                                            [key] => doc_type
                                                            [value] => jpg
                                                        )

我想打印每个文档的file_Type值,请帮助我如何实现它。

2 个答案:

答案 0 :(得分:0)

基本上首先需要在循环中获取元值,然后提取它,例如:

Timings

答案 1 :(得分:0)

基本上,您可以在模型上添加关系:

在您的模型上:

public function TableMeta()
{
    return $this->hasMany('App\Models\TableMeta');
}

然后在您的控制器上

$query = Model::with('TableMeta')->get();