在使用关系的前端laravel中的分页

时间:2017-12-18 03:02:59

标签: php laravel

>

我想在类别视图中使用分页。我只想显示使用slug选择的5个特定类别的帖子。 我想要下面的分页链接。

这是我的观点:

@extends('layouts.frontend')

@section('content')

    <!-- Stunning Header -->

<div class="stunning-header stunning-header-bg-lightviolet">
    <div class="stunning-header-content">
        <h1 class="stunning-header-title">Category:{{$category->name}}</h1>
    </div>
</div>

<!-- End Stunning Header -->

<div class="container">
    <div class="row medium-padding120">
         <main class="main">

            <div class="row">
                @php
                    $i = 0;
                @endphp

                    @foreach($category->posts as $post)
                        <div class="case-item-wrap">
                            <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                                <div class="case-item" style="margin-top: 20px;">
                                    <div class="case-item__thumb">
                                        <img src="{{$post->featured}}" alt="our case">
                                    </div>
                                    <h6 class="case-item__title"><a href="{{route('post.single',['slug' => $post->slug])}}">{{$post->title}}</a></h6>
                                </div>
                            </div>
                        </div>
                        @php $i++; @endphp
                        @if($i % 3 == 0)
                            <div class="row"></div>
                        @endif
                    @endforeach


            </div>
    </div>




        </main>
    </div>
</div>


@endsection

这是我的前端控制器。我想在哪里选择具有特定类别的帖子然后在我的视图中显示5个号码。在如何使用实际分页方面存在问题。

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Setting;
use App\Category;
use App\Post;
use App\User;
use App\Tag;

class FrontEndController extends Controller
{
    public function index()
    {   
        $title = Setting::first()->site_name;
        $categories = Category::all();
        $first_post = Post::latest()->first();
        $second_post = Post::latest()->skip(1)->take(1)->get()->first();
        $third_post = Post::latest()->skip(2)->take(1)->get()->first();
        $english_11 = Category::find(1);
        $blog = Category::find(3);
        $settings = Setting::first();
        $tags = Tag::all();


        return view('index',compact('title','categories','first_post','second_post','third_post','english_11','blog','settings','tags'));
    }

    public function singlePost($slug)
    {
        $categories = Category::all();
        $settings = Setting::first();
        $post = Post::where('slug',$slug)->first();
        $next_id = Post::where('id','>',$post->id)->min('id');
        $prev_id = Post::where('id','<',$post->id)->max('id');
        $next = Post::find($next_id);
        $prev = Post::find($prev_id);
        $tags = Tag::all();
        $title = $post->title;
        return view('single',compact('post','title','categories','settings','next','prev','tags'));
    }

    public function categories($slug)
    {
        $category = Category::where('slug',$slug)->first();
        $categories = Category::all();
        $title = $category->name;
        $settings = Setting::first();

        return view('category',compact('category','categories','title','settings'));

    }

     public function tags($slug)
    {
        $tag = Tag::where('slug',$slug)->first();
        $categories = Category::all();
        $title = $tag->tag;
        $settings = Setting::first();

        return view('tag',compact('tag','categories','title','settings'));

    }
}

0 个答案:

没有答案