Neeraj1005
1 month ago
555
8
Laravel

Method Illuminate\Database\Eloquent\Collection::links does not exist. (View: C:\xampp\htdocs\mylearnwork\codehacking\resources\views\themes\blog\blog_front.blade.php)

Posted 1 month ago by Neeraj1005

Basically in my project I'm trying to fiter the post by using category I am getting the post but pagination is not working. can anyone give the suggestion where did I make mistake? controller code

public function bloglist() {

        $blogs = Post::with('photo','user')->latest();

        if (request('category')) {

            $categoryname = request('category');

            $blogs = $blogs->when($categoryname, function($query, $categoryname) {
                $query->withCategory($categoryname);
            })->paginate(2)->append('category',$categoryname);

        } else {

            $blogs = $blogs->paginate(3);
        }

        return view('themes.blog.blog_front',compact('blogs'));
    }

and this is my blade file links code

<x-blog.app >

    @section('title', 'Page')

    @forelse($blogs as $blog)
    <div class="max-w-sm w-full lg:max-w-full lg:flex my-1">
        <div class="h-48 lg:h-auto lg:w-48 flex-none bg-cover rounded-t lg:rounded-t-none lg:rounded-l text-center overflow-hidden"
        style="background-image: url('{{ $blog->photo->file }}')" title="Woman holding a mug">
        </div>
        <div class="border-r border-b border-l border-gray-400 lg:border-l-0 lg:border-t lg:border-gray-400 bg-white rounded-b lg:rounded-b-none lg:rounded-r p-4 flex flex-col justify-between leading-normal">
          <div class="mb-8">
            <div class="text-gray-900 font-bold text-xl mb-2">{{ $blog->title ?? '' }}</div>
            <p class="text-gray-700 text-base">
                {{ $blog->shortDescription() ?? '' }}
            </p>
          </div>
          <div class="flex items-center">
            <img class="w-10 h-10 rounded-full mr-4" src="{{url('images/jonathan.jpg')}}" alt="Avatar of Jonathan Reinink">
            <div class="text-sm">
              <p class="text-gray-900 leading-none">{{ $blog->user->name }}</p>
              <p class="text-gray-600">{{ $blog->created_at->isoFormat('MMM YYYY') }}</p>
            </div>
          </div>
        </div>
    </div>
    @empty
        {{('No blogs Available')}}
    @endforelse
    {{ $blogs->links('vendor.pagination.tailwind') }}

</x-blog.app>

Please sign in or create an account to participate in this conversation.