douzhong5902 2016-11-13 12:50
浏览 175
已采纳

未定义属性:Illuminate \ Pagination \ LengthAwarePaginator :: $ id(查看:F:\ project esources \ views \ admin \ carousels \ index.blade.php)

when I try to pass variable data to view I get this error, I can't find any document about this problem My controller(CarouselController.php)

    public function index()
{
$carousels = Carousel::orderBy('created_at', 'asc')->paginate(12);
return view('admin.carousels.index')->withCarousels($carousels);
}

My view(index.blade.php)

<div class="row">
    <div class="col-md-9">
        <h1>All Images</h1>
    </div>
    <div class="col-md-3">
        <a href="{{ route('carousels.create') }}" class="btn btn-lg btn-block btn-primary  ">Create New carousel</a>
    </div>
    <div class="col-md-12">
        <hr>
    </div>
</div>{{-- end of the row --}}
<div class="row">
    <div class="col-md-12">
            <div class="row">
     @foreach($carousels as $photo)
        <div class="col-xs-6 col-md-3">
        {!!  Form::open( array('route'=>array('carousels.destroy', $carousels->id),'method'=>'DELETE')) !!}

        {!! Form::submit('Delete', array('class'=>"btn btn-danger btn-sm tours-delete tour-index-delete"))!!}

        {!! Form::close() !!}
        <a href="{{ url($photo->path) }}" class="thumbnail" data-lity>
        <img class="img-responsive" src="{{ $photo->path }}" alt="">
        </a>
        </div>
     @endforeach

</div>
    </div>
    <div class="text-center">
            {!! $carousels->links(); !!}
    </div>
</div>
  • 写回答

1条回答 默认 最新

  • douxueke5653 2016-11-13 12:59
    关注

    You foreach loop contains the code:

    $carousels->id;
    

    which seems to be getting a single object from collection, which isn't the right way, you should try this:

    @foreach($carousels as $carousel)
      <div class="col-xs-6 col-md-3">
      {!!  Form::open( array('route'=>array('carousels.destroy', $carousel->id),'method'=>'DELETE')) !!}
    
      {!! Form::submit('Delete', array('class'=>"btn btn-danger btn-sm tours-delete tour-index-delete"))!!}
    
      {!! Form::close() !!}
      <a href="{{ url($carousel->path) }}" class="thumbnail" data-lity>
      <img class="img-responsive" src="{{ $carousel->path }}" alt="">
      </a>
      </div>
    @endforeach
    

    Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算