2016-09-05 2 views
1

特定のユーザーが行った結果を表示するには、いくつかの問題があります。Laravel Eager読み込み中|特定のユーザーのクエリ

以下のコードでは、すべてのエントリ($ restaurantmenue)を受け取る代わりに、特定のユーザーによって作成されたエントリのみが必要です。エントリを作成するユーザに対してのみどのようにクエリを実行できますか? Article.phpでnowpublished

//Restaurant Profile Page 
public function showrestaurants($id) { 
    $restaurant = User::findOrFail($id); 
    //$restaurant->addclick(); 

    $restaurantmenue = User::with(['articles' => function ($q){ 
    $q->nowpublished(); 
    }])->get(); 

    return view('pages.profile')->withRestaurant($restaurant)->withRestaurantmenue($restaurantmenue); 
} 

()範囲:

public function scopeNowPublished($query) { 
    $zero = Carbon::today()->addHours(23)->addMinutes(59)->addSeconds(59); 
    $query->whereBetween('published_at',[Carbon::today(),$zero])->orderBy('published_at','desc'); 
} 

マイビュー:

@foreach($restaurantmenue as $daily) 
        @foreach($daily->articles as $menue) 
        <div class="card card-horizontal"> 
         <div class="row"> 
         <div class="col-md-5"> 
          <div class="image" style="background-image: url({{asset('images/frontend/profile/profileHero.jpg')}}); background-size: cover; background-position: center center;"> 
          <img src="{{asset('images/frontend/profile/profileHero.jpg')}}" alt="..." style="display: none;"> 
          <div class="filter filter-azure"> 
           <button type="button" class="btn btn-neutral btn-round"> 
            <i class="fa fa-heart"></i> SMÄCKT MIR 
           </button> 
          </div> 
          </div> 
         </div> 
         <div class="col-md-7"> 
          <div class="content"> 
           <p class="category text-info"> 
            <i class="fa fa-trophy"></i> Best of 
           </p> 

           <a class="card-link" href="#"> 
            <h4 class="title">{{$menue->title}} </h4> 
           </a> 
           <a class="card-link" href="#"> 
            <p class="description">{{$menue->body}}</p> 
            <br /> 
            {{$menue->price}} € 
           </a> 

          </div> 
         </div> 
         </div> 
        </div> 
        @endforeach 
       @endforeach 

答えて

2

私が正しくあなたを理解している場合、あなたはこのような何かを行う必要があります。

$restaurantmenue = User::where('id', $id)->with(['articles' => function ($q) { 
    $q->nowpublished(); 
}])->get(); 
+1

完了!これは役に立ちます – Mamulasa

+0

喜んで助けました。 ) –

関連する問題