Show n posts from a specific category in homepage

Solved
francescomulassano1

Dec 23rd, 2022 05:30 AM

Hi, in wave i want to show the latest 3 posts from the blog in another page i want to show the latest 3 posts from a specific category, how to achieve these results?

Thanks

francescomulassano1

Dec 23rd, 2022 06:50 AM

find a solution, is it right?

<?php

namespace Wave\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Wave\Post;
use Wave\Category;


class HomeController extends Controller
{

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
    	if(setting('auth.dashboard_redirect', true) != "null"){
    		if(!Auth::guest()){
    			return redirect('dashboard');
    		}
    	}

        $posts = Post::orderBy('created_at', 'DESC')->paginate(3);
        $categories = Category::all();

        $seo = [

            'title'         => setting('site.title', 'Laravel Wave'),
            'description'   => setting('site.description', 'Software as a Service Starter Kit'),
            'image'         => url('/og_image.png'),
            'type'          => 'website'

        ];

        return view('theme::home', compact('seo', 'posts', 'categories'));
    }
}
bobbyiliev

Dec 23rd, 2022 09:56 AM

Best Answer

Hi there,

Yep, this looks good!

Let me know if anything else pops up!

Best,

Bobby