1

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"
      ],
],
2
  • 1
    Show the config/constants.php config please. Commented Apr 10, 2017 at 20:04
  • @AlexeyMezenin, I added constants.php Commented Apr 10, 2017 at 20:06

1 Answer 1

4

Since it's array of arrays, do this:

@foreach (config('constants.pressMetadata') as $tile)
    <p>{{ $tile['id'] }}</p>
@endforeach
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.