【问题标题】:How to array data from @foreach in Laravel Views如何在 Laravel 视图中排列来自 @foreach 的数据
【发布时间】:2017-02-25 21:43:25
【问题描述】:

我知道这是可能的,但我尝试从网上搜索但我从未找到答案,所以如果有人知道如何使用 Laravel View 从@foreach 将数据推送到数组,请帮助我。提前致谢

这里是代码

@foreach ($fields as $key => $rel)

 {{ $arrayData = array(

    'field_type' =>'$rel->field_type'
 )}}

@endforeach

我收到的错误是

helpers.php 第 519 行中的错误异常: htmlspecialchars() 期望参数 1 是字符串,给定数组(查看:C:\xampp\htdocs\fields.blade.php)

【问题讨论】:

    标签: php arrays foreach laravel-5.3


    【解决方案1】:

    从 $rel->field_type 中删除引号

    @foreach ($fields as $key => $rel)
    
     {{ $arrayData = array(
    
        'field_type' =>$rel->field_type
     )}}
    
    @endforeach
    

    【讨论】:

    • 错误先生 a Use of undefined constant field_type - 假定为“field_type”(查看:C:\xampp\htdocs\papers\resources\views\admin\fields.blade.php)
    • 你能在 foreach 循环之前打印 print_r($fields) 并更新问题吗?我认为 field_type 不在数组中
    • { “field_id”:82,“field_name”:“field_name”,“field_slug”:“field_slug”,“field_label”:“field_label”,“field_type”:“text”,}跨度>
    • @Paul.can you post print print_r($fields)的所有数据因为数据不是数组
    • 哎呀我的错让我发送输出图像
    猜你喜欢
    • 1970-01-01
    • 2019-08-31
    • 2020-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2023-03-26
    相关资源
    最近更新 更多