簡體   English   中英

如何在刀片Laravel中顯示元鍵值

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

請任何人告訴我如何在查看輸出的數組下面顯示元鍵值:

[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值,請幫助我如何實現它。

基本上,為此,首先需要循環獲取元值,然后將其提取出來,例如:

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

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

                        }
}
echo $metaArg1['doc_Type'];

                    ?>

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

在您的模型上:

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

然后在您的控制器上:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM