first upload all files
This commit is contained in:
66
Modules/Admin/Http/Controllers/Admin/DashboardController.php
Normal file
66
Modules/Admin/Http/Controllers/Admin/DashboardController.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\Http\Controllers\Admin;
|
||||
|
||||
use Modules\Order\Entities\Order;
|
||||
|
||||
class SalesAnalyticsController
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Modules\Order\Entities\Order $order
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Order $order)
|
||||
{
|
||||
return response()->json([
|
||||
'labels' => trans('admin::dashboard.sales_analytics.day_names'),
|
||||
'data' => $order->salesAnalytics(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user