Rainieren
1 year ago

Laravel - More effiecient way to count attributes.

Posted 1 year ago by Rainieren

Hello, I have a page where I want to count the number of Posts, Users and comments. But currently, i'm doing it like this. and It looks a bit odd.

public function index()
    {
        $posts = Post::all();
        $users = User::all();
        $comments = Reply::all();

        return view('admin.dashboard')->with('posts', $posts)->with('users', $users)->with('comments', $comments);
    }

Is there a cleaner and better way to accomplish this? Thanks

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