Level 46
Yeah, name isn't a property of a LengthAwarePaginator.
$category = Category::where('slug', $slug)->first()
I suspect you want to paginate the $categories.
$categories = Categories::paginate(5)
Undefined property: Illuminate\Pagination\LengthAwarePaginator::$name
public function categories($slug)
{
$category = Category::where('slug',$slug)->paginate(5);
$categories = Category::all();
$title = $category->name;
$settings = Setting::first();
return view('category',compact('category','categories','title','settings'));
}
Yeah, name isn't a property of a LengthAwarePaginator.
$category = Category::where('slug', $slug)->first()
I suspect you want to paginate the $categories.
$categories = Categories::paginate(5)
how do I use Pagination here??
Updated my reply ...
see. I have 4 categories with slug. When i click category HTML . I want 5 post with category html . ty for your time. :)
5 posts? you have not mentioned posts in your question or code?
Also show your view
This is my view
@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
And this is my fronendcontroller
<?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'));
}
}
Please or to participate in this conversation.