67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\Admin\Http\Controllers\Admin;
|
|
|
|
use Modules\User\Entities\User;
|
|
use Modules\Order\Entities\Order;
|
|
use Modules\Review\Entities\Review;
|
|
use Modules\Product\Entities\Product;
|
|
use Modules\Product\Entities\SearchTerm;
|
|
|
|
class DashboardController
|
|
{
|
|
/**
|
|
* Display the dashboard with its widgets.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('admin::dashboard.index', [
|
|
'totalSales' => Order::totalSales(),
|
|
'totalOrders' => Order::withoutCanceledOrders()->count(),
|
|
'totalProducts' => Product::withoutGlobalScope('active')->count(),
|
|
'totalCustomers' => User::totalCustomers(),
|
|
'latestSearchTerms' => $this->getLatestSearchTerms(),
|
|
'latestOrders' => $this->getLatestOrders(),
|
|
'latestReviews' => $this->getLatestReviews(),
|
|
]);
|
|
}
|
|
|
|
private function getLatestSearchTerms()
|
|
{
|
|
return SearchTerm::latest('updated_at')->take(5)->get();
|
|
}
|
|
|
|
/**
|
|
* Get latest five orders.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
|
*/
|
|
private function getLatestOrders()
|
|
{
|
|
return Order::select([
|
|
'id',
|
|
'customer_first_name',
|
|
'customer_last_name',
|
|
'total',
|
|
'status',
|
|
'created_at',
|
|
])->latest()->take(5)->get();
|
|
}
|
|
|
|
/**
|
|
* Get latest five reviews.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
|
*/
|
|
private function getLatestReviews()
|
|
{
|
|
return Review::select('id', 'product_id', 'reviewer_name', 'rating')
|
|
->has('product')
|
|
->with('product:id')
|
|
->limit(5)
|
|
->get();
|
|
}
|
|
}
|