laravel前台图片轮播功能

Model层Slide:

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Slide extends BaseModel
{
protected$fillable= [
//声明变量
‘title’, ‘btn_txt’, ‘btn_url’, ‘img_url’,’sort’,’status’
];
}

控制器层:

public function index()
{
$slides_all= Slide::orderBy(‘id’,’asc’)->paginate(10);
return view(‘home’, compact(‘slides_all’));
}
前台view层form:
<!– Wrapper for slides 从第一页开始轮播–>
<div class=”carousel-inner”role=”listbox”>
@foreach($slides_all as $key => $value)
<div class=”item @if($key ==0) active @endif”>
<img src=”{{ asset(‘/uploads/’ . $value->img_url) }}”alt=”…”>
<div class=”carousel-caption”>
<div class=”container”>
<h2>{{$value->title}}</h2>
<a class=”btn btn-lg btn-leran-more”href=”{{$value->btn_url}}”><i class=”fa fa-info-circle”aria-hidden=”true”></i> {{$value->btn_txt}}</a>
</div>
</div>
</div>
@endforeach

679 total views, 6 views today

Revisions

There are no revisions for this post.

No comments yet.

发表评论