Passing multiple variables to a single view Laravel

In my controller:

In my controller:

public function index()
{
    $userTotal = User::all();
    $userActive = User::where('status', '=', 'Active');
    $userInactive = User::where('status', '=', 'Inactive');
    $userOnAndOff = User::where('status', '=', 'OnAndOff');
return view('member.home')
    ->with(compact('userTotal'))
    ->with(compact('userActive'))
    ->with(compact('userInactive'))
    ->with(compact('userOnAndOff'));

}

In my view:

<div class="card border-success">
<div class="card-horizontal">
<div class="card-body bg-success">
<p class="card-text text-white bg-success text-md-center"><i class="fas fa-users fa-2x"></i></p>
</div>
<div class="card-body text-success">
<p class="card-text">Registered Member: <strong>{{ $userTotal->count() }}</strong></p>
<p class="card-text">Active Members: <strong>{{ $userActive->count() }}</strong></p>
<p class="card-text">Active Members: <strong>{{ $userActive->count() }}</strong></p>
<p class="card-text">Inactive Members: <strong>{{ $userInactive->count() }}</strong></p>
</div>
</div>
</div>

I am trying to print out count values, is there any better way to code the controller?

Laravel Development Company | Hire Laravel Developer

Laravel Development Company | Hire Laravel Developer

Get a free quote for custom Laravel Development Services from a trusted Laravel web development company. Hire Laravel Developers now @ best affordable rates

Get a free quote for custom Laravel Development Services from a trusted Laravel web development company. Hire Laravel Developers now at best affordable rates

Laravel Tutorial - Abusing Laravel

Laravel Tutorial - Abusing Laravel

Laravel Tutorial - Abusing Laravel: In this talk, Gustavo takes a look at the importance of Unit Tests and how Dependency Injection, which is often not promoted by Laravel docs, can help to achieve Unit Testing.

In this talk, Gustavo takes a look at the importance of Unit Tests and how Dependency Injection, which is often not promoted by Laravel docs, can help to achieve Unit Testing.

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow us on Facebook | Twitter

Further reading about Laravel

Laravel 5.8 Tutorial for Beginners

Learn GraphQL with Laravel and Vue.js - Full Tutorial

Export or Import of CSV or Excel file in Laravel 5.8 with MySQL

Laravel 5.8 CRUD Tutorial With Example Step By Step

Build RESTful API In Laravel 5.8 Example

Get Weather Data with Laravel Weather

Get Weather Data with Laravel Weather

Get Weather Data with Laravel Weather. Laravel Weather is a good package which we can use to get weather data. It's a wrapper around Open Weather Map API (Current weather). A wrapper around Open Weather Map API (Current weather)

🌤️ A wrapper around Open Weather Map API (Current weather)

Installation

You can install the package via composer:

source-shell
composer require gnahotelsolutions/laravel-weather
Usage
text-html-php
$weather = new Weather();

// Checking weather by city name
$currentWeatherInGirona = $weather->get('girona,es');

// You can use the city id, this will get you unambiguous results
$currentWeatherInGirona = $weather->find('3121456');

Units

By default the package uses metric for Celsius temperature results, this can be modified using the configuration file or on the fly:

text-html-php
$weather = new Weather();

$currentWeatherInGirona = $weather->inUnits('imperial')->get('girona,es');

Language

By default the package uses es for the description translation, this can be modified using the configuration file or on the fly:

text-html-php
$weather = new Weather();

$currentWeatherInGirona = $weather->inLanguage('en')->get('girona');

Guzzle Client Instance

If you need to use another instance of Guzzle, to modify headers for example:

text-html-php
$weather = new Weather();

$guzzle = $this->getSpecialGuzzleClient();

$currentWeatherInGirona = $weather->using($guzzle)->get('girona');

Testing

source-shell
composer test