2016-08-26 22 views
1

"welcome"ページから "profile"ページへのリンクで何がうまくいかないのか分かりません。Laravel不一致変数ビュー

奇妙なひもが、私は変数にを渡すことである

それは「::レストラン(ビュー/Users/beyerdynamic/Documents/Developer/dev1/resources/views/welcome.blade.php)未定義変数」と言います私の見解。

私をPagesControllerは次のとおりです。

@foreach($restaurants as $key => $restaurant) 
      <div class="col-md-4"> 
       <div class="card"> 
        <div class="image"> 
         <img src="{{asset('images/frontend/profile/dummy/profilehero/hero4.png')}}" alt="..." /> 
         <div class="filter filter-white"> 
          <a href="{{ URL::to('profile/'.$restaurant->id)}}" type="button" class="btn btn-info btn-round btn-fill"> 
           <i class="fa fa-heart"></i> View Restaurant 
          </a> 
         </div> 
        </div> 
       </div> 
      </div> 
      @endforeach 

レストラン変数が私の歓迎ビューに適切に渡されますが、私は、リンクをクリックしたときにエラーが/ /プロファイルに発生します。

public function welcome() { 
    $restaurants = User::orderByRaw('RAND()')->take(3)->get(); 
    return view('welcome')->withRestaurants($restaurants); 
} 

私のビューがあります{id} URL。

+0

'プロファイル/ {ID}が何である'あなたはそれについて何も共有しませんでしたか? –

+0

'Profile/{id}'と 'routes.php'のコントローラーコードを共有します –

+1

@Iftikharuddin uddin:プロフィールのコントローラ/¥{id}にチェックされています。エラーがそこにありました。ありがとう – Mamulasa

答えて

0

変更するには、次の行:

return view('welcome', array('restaurants' => $restaurants)); 

return view('welcome')->withRestaurants($restaurants); // there is nothing like withRestaurants in laravel 

し、再試行してください。

+0

同じひも未定義の変数:レストラン(表示:/Users/beyerdynamic/Documents/Developer/dev1/resources/views/welcome.blade.php) – Mamulasa

+0

私は答えを編集しました。これを試してみてください。 –

0

変更return view('welcome')->withRestaurants($restaurants);

return view('welcome')->with('restaurants', $restaurants); 

OR

return view('welcome', compact('restaurants'); 
+0

Error.ExceptionのView.php行182: 不正なオフセットタイプ – Mamulasa

+0

上記のコードを試しましたか?もう一度見てください。 –

+0

間違ったコードを試しましたが、新しいものを試してみてください。 '戻り値( '歓迎') - >( 'レストラン'、$レストラン); ' –

0

に、これで

return view('welcome')->with("restaurants",$restaurants); 

OR

をお試しください
return view('welcome',["restaurants" => $restaurants]); 

チェックlaravelドキュメント:https://laravel.com/docs/master/views#passing-data-to-views

+0

リシ、同じこと、私が混乱しているのは、このエラー "未定義変数:レストラン(ビュー:/Users/beyerdynamic/Documents/Developer/dev1/resources/views/welcome.blade.php)"がウェルカムビューに表示されません。それはプロフィールビューで発生します – Mamulasa

+0

ようこそページのルートは何ですか? – C2486

+0

'welcome'ページのルートが' welcome'なら 'return redirect( 'welcome'、[" restaurants "=> $ restaurants]);' – C2486

関連する問題