dongnanke4106 2017-04-10 20:02
浏览 44
已采纳

在Laravel中访问配置变量

Under my config folder I have a constants.php file. I have accessed pressMetadata object in the constant file using {{ json_encode(config('constants.pressMetadata')) }}. This dumps all the data as a JSON object. What I am trying to do is print out all the data using a foreach loop. I have tried

@foreach (config('constants.pressMetadata') as $tile)
          <p>{{$tile->id}}</p>
@endforeach

This does not work. So what should I do so I can use a foreach loop to iterate through the object at config('constants.pressMetadata')?

Here is constants pressMetadata

'pressMetadata'=>[
      "AARP" => [
          "id" => 1,
          "company" => "AARP",
          "title" => "Updating Your Résumé for the Digital Age",
          "url" => "http://www.aarp.org/work/job-hunting/info-2016/give-resume-a-digital-reboot.html",
          "date" => "Sep 9, 2016"
      ],
      "Business Insider" => [
          "id" => 2,
          "company" => "Business Insider",
          "title" => "8 things you should always include on your résumé",
          "url" => "http://www.businessinsider.com/what-to-always-include-on-your-resume-2016-1",
          "date" => "Jan 28, 2016"
      ],
      "Morning Journal" => [
          "id" => 3,
          "company" => "Morning Journal",
          "title" => "5 things you missed: Google updates search, Jobscan and more",
          "url" => "http://www.morningjournal.com/article/MJ/20140124/NEWS/140129366",
          "date" => "Jan 24, 2014"
      ],
],
  • 写回答

1条回答 默认 最新

  • doulin3510 2017-04-10 20:07
    关注

    Since it's array of arrays, do this:

    @foreach (config('constants.pressMetadata') as $tile)
        <p>{{ $tile['id'] }}</p>
    @endforeach
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏