php - Laravel foreach issues -


i stuck on foreach loop inside blade template after hours of trial , failure need help.

my controller

public function menue() {    $restaurants = user::with('articles')->get();;    return view('pages.menues')->withrestaurants($restaurants); } 

my foreach

@foreach($restaurants $restaurant)          <div class="panel panel-default">           <div class="panel-heading">             @foreach($restaurant->articles $article)               {{$article->title}}               <span class="float-right">{{$article->published_at}}</span>             @endforeach           </div>            <div class="panel-body">             @foreach($restaurant->articles $article)               {{$article->body}}             @endforeach              {{$restaurant->name}}            </div>         </div>        @endforeach 

this i'm trying loop trough:

    {          "id":1,        "name":"sam",        "email":"sam@me.com",        "created_at":"2016-07-26 15:03:51",        "updated_at":"2016-07-27 15:39:55",        "articles":[             {                "id":1,              "user_id":1,              "title":"monday afternoon",              "body":"got it",              "created_at":"2016-07-27 15:31:05",              "published_at":"2016-07-27 15:30:00",              "excerpt":null,              "updated_at":"2016-07-27 15:31:05"           },           {                "id":3,              "user_id":1,              "title":"good morning wednesday",              "body":"lorem ipsum",              "created_at":"2016-07-27 11:38:37",              "published_at":"2016-07-27 11:38:00",              "excerpt":null,              "updated_at":"2016-07-27 11:38:37"           },           {                "id":4,              "user_id":1,              "title":"good morning thursday",              "body":"lorem ipsum ",              "created_at":"2016-07-27 11:39:14",              "published_at":"2016-07-28 14:38:00",              "excerpt":null,              "updated_at":"2016-07-27 11:39:14"           },           {                "id":5,              "user_id":1,              "title":"wednesday afternoon",              "body":"hallo welt",              "created_at":"2016-07-27 14:55:00",              "published_at":"2016-07-27 14:54:00",              "excerpt":null,              "updated_at":"2016-07-27 14:55:00"           }        ]     } 

output of blade template output of blade

the result instead of 4 posts 2 posts. each of them contains other posts. how can display 4 posts individually in view?

try

@foreach($restaurants $restaurant)   @foreach($restaurant->articles $article)     <div class="panel panel-default">       <div class="panel-heading">         {{$article->title}}         <span class="float-right">{{$article->published_at}}</span>       </div>       <div class="panel-body">{{$article->body}}</div>     </div>   @endforeach @endforeach 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -