如何获取具有视频ID的类别的视频?

时间:2020-03-21 13:31:40

标签: laravel-5.8

我有一个category_video,只有39和40。

table

看看我的密码。

web.php

Route::get('/videos/category/{category_id}', 'CategoryController@video')->name('category.video');

CategoryController.php

public function video($id)
{
    $category = Category::where('id', $id)->first();
    $videos = $category->catVideos()->paginate(25);
    return view('Home.categories.videos', compact('category', 'videos'));
}

videos.blade.php

<div class="bg-white">
    <div class="container">
        <h2 class="mb-5 mt-5">{{ $category->name }}</h2>
        <div class="row">
            @foreach($videos as $video)
                @foreach($video->catVideos as $c)
                    <div class="col-md-3 col-sm-6 col-12">
                        <div class="image_tn rounded border mb-2">
                            <a href="{{ asset('public/videos/'.$c->video) }}" data-showsocial="true" data-thumbnail="{{ asset('public/videos/'.$c->image) }}" class="html5lightbox" data-group="set1" data-width="800" data-height="600" title="{{ $c->title }}">
                                <img src="{{ asset('public/videos/'.$c->image) }}" class="img-fluid d-block mx-auto rounded" alt="{{ $c->title }}"/>
                            </a>
                        </div>
                    </div>
                @endforeach
            @endforeach
        </div>
    </div>
</div>

Category.php

public function catVideos()
{
    return $this->belongsToMany(Video::class);
}

当我单击ID为39的类别时。

显示ID等于39的视频。但是我看到的是39和40。

0 个答案:

没有答案