laravel 5.6 carousel bootstrap

时间:2018-04-27 19:05:04

标签: php laravel carousel

我正在上一次考试。

所以,可能有一些显而易见的事情,我没有看到。

我创建了一个工作正常的旋转木马。

问题在于,当我调用数据时,它不会循环遍历我的所有数据:screenshot of the carousel

修改

对不起,我觉得我不够清楚:

我设法获得了所有数据。 db有4个项目,名为项目1,项目2,项目3和项目4。

我的问题是,当我通过我的foreach()循环时,只有一张幻灯片移动:第一张幻灯片。

我的索引视图:

    @extends('layouts.app')
    @section('content')
    <br>
    <br>
    <br>
    <title>{{$title}}</title>
            <h1 class="text-center">This is my work:</h1>
            <br>
            <br>
    <div id="carouselExampleIndicators" class="carousel slide" data-

ride="carousel">
        @foreach($projects as $project)
            <div class="carousel-inner text-center" role="listbox">
                <div class="carousel-item active">
                    <h2>{{$project->name}}</h2>
                    <img class="d-block w-100 img-fluid" src="{{asset('Caroussel/laravel.png')}}" height="150" width="150">
                    <p>{{$project->description}}</p>
                    <!--TAGS-->
                </div>

                <div class="carousel-item">
                        <h2>{{$project->name}}</h2>
                        <img class="d-block w-100 img-fluid" src="{{asset('Caroussel/chatbot.png')}}" height="150" width="150">
                        <p>{{$project->description}}</p>
                        <!--TAGS-->
                </div>

                <div class="carousel-item">
                        <h2>{{$project->name}}</h2>
                        <img class="d-block w-100 img-fluid" src="{{asset('Caroussel/iot.png')}}" height="150" width="150">
                        <p>{{$project->description}}</p>
                        <!--TAGS-->
                </div>

                <div class="carousel-item">
                        <h2>{{$project->name}}</h2>
                        <img class="d-block w-100 img-fluid" src="{{asset('Caroussel/php.png')}}" height="150" width="150">
                        <p>{{$project->description}}</p>
                        <!--TAGS-->
                </div>
            </div>
        @endforeach

        <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>

        <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
        </a>
    </div> 
    @endsection

控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Project;
use App\Tag;

class ProjectController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $title = 'My work';
        $projects = Project ::all();
        return view('projects.index')->with('title',$title)->with('projects',$projects);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

我的&#34;项目&#34;模型:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Project extends Model
{
    public function tags(){
        return $this->belongsToMany('App\Tag','project_tag','projects_id','tags_id');        
    }

}

感谢您的帮助!

0 个答案:

没有答案