简体   繁体   English

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

[英]How to display meta key value in blade Laravel

Please can any one tell me how I can show the meta key value in view the array which im getting output is below: 请任何人告诉我如何在查看输出的数组下面显示元键值:

[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
                                                        )

I want to print the file_Type value of each document please help me how can I achieve it. 我想打印每个文档的file_Type值,请帮助我如何实现它。

Basically for this First need to get the meta value in loop and then extract it for example: 基本上,为此,首先需要循环获取元值,然后将其提取出来,例如:

 <?php
foreach($folderFiles as $file)
                $metaArg1=array();
                        foreach ($file->ResourceMeta as $key => $value) {

                            $metaArg1[$value->key] = $value->value;

                        }
}
echo $metaArg1['doc_Type'];

                    ?>

Basically you can add a relationship on your model: 基本上,您可以在模型上添加关系:

On your model: 在您的模型上:

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

Then on your controller: 然后在您的控制器上:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM