变量似乎没有从控制器传递到视图

Variable doesn't seem to be passing from controller to to view

我正在尝试将变量从控制器路由传递到视图,以便我可以显示与新关联模型相关的数据。它适用于其他控制器,但我不明白为什么它不在这里。

控制器 @Index - 没有向下传递

public function index(){
  $Advert = new PropertyAdvert();

  return view('pages/Advert/index', compact('Advert'));
}

@Show - 正在运行,这只是一个示例。

    public function show($id){
        $user = Auth::user();
        $Advert = PropertyAdvert::where('id', $id)->first();
        return view('pages/Advert/show', compact('Advert', 'user'));
    }

这是路线

Route::get('/property', 'AdvertisementController@index');
Route::get('/advertise', 'AdvertisementController@create')->middleware('auth');
Route::post('/createadvert', 'AdvertisementController@store');
Route::get('/property/{id}', 'AdvertisementController@show');

这是我要传递给 show.blade.php

的模板
<div class="row text-center" style="display:flex; flex-wrap:wrap">
        <div class="col-lg-12">
            <h3>Our most recent properties</h3>
            @foreach ($Advert as $property)
              <div class="col-md-3 col-sm-6">
                  <div class="thumbnail">
                      <img src="data:image/gif;base64,{{ $property->photo }}">
                      <div class="caption">
                          <h4>{{$property->address .', '. $property->town .', '. $property->county}}</h4>
                      </div>
                      <p>
                          <a href="#" class="btn btn-primary">More Info!</a>
                      </p>
                  </div>
              </div>
            @endforeach
        </div>
    </div>
</div>

试试这个:

public function index(){
  $Advert = PropertyAdvert::get();

  return view('pages/Advert/index', compact('Advert'));
}

您需要实际访问该模型的数据。