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

未定义属性: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!

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题