henryoladj
1 week ago

I want to display latest posts on my laravel home page

Posted 1 week ago by henryoladj

Controller.php

public function index(Request $request)
    {
       
        if($request->has('tags')){
            $tag=Tag::find($request->tags);
            $news=$tag->news;
        }else{
        $news = News::with(['post' => function($query) {
        return $query->latest()->limit(5)->paginate(15);
        }])->get(); 
        }
        return view('pages.welcome',compact('news', 'tags'));
    }

I want the post lists to be displayed according to the latest posts made.

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