hasibweb
3 weeks ago
107
4
Laravel

How to pluralise word in Laravel?

Posted 3 weeks ago by hasibweb

Hello.

I want to plural a word in Laravel based on user count. For example, I want to count list of the users. If total count is more than 1, then it should return users otherwise, user.

Here is my code-

In controller.

$users = User::get();
return view('users.index', compact('users'))

In view-

@if($users->count() > 1)
    {{ $users->count() }} Users
@else 
    {{ $users->count() }} User
@endif    

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