Skip to content

Commit

Permalink
Some small refactoring
Browse files Browse the repository at this point in the history
1. A small refactor to app/Exceptions/Handler.php
2. Try count 6 different metrics at once to save some database
   roundtrips.

Signed-off-by: Xiaoguang Sun <sunxiaoguang@gmail.com>
  • Loading branch information
sunxiaoguang committed Apr 28, 2024
1 parent 45ac897 commit 89598f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
16 changes: 5 additions & 11 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,11 @@ public function render($request, Throwable $exception)
{
// return parent::render($request, $exception);
if ($exception instanceof HttpExceptionInterface) {
if (env('APP_ENV') === 'production' && $exception->getCode() == 403) {
return response()->view('errors.403', [], 403);
}
if (env('APP_ENV') === 'production' && $exception->getCode() == 404) {
return response()->view('errors.404', [], 404);
}
if (env('APP_ENV') === 'production' && $exception->getCode() == 419) {
return response()->view('errors.419', [], 419);
}
if (env('APP_ENV') === 'production' && $exception->getCode() == 500) {
return response()->view('errors.500', [], 500);
if (env('APP_ENV') === 'production') {
$code = $exception->getCode();
if (in_array($code, [403, 404, 419, 500])) {
return response()->view("errors.{$code}", [], $code);
}
}
}

Expand Down
19 changes: 12 additions & 7 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ public function index()
$userRoleCount = $user->getRoleNames()->count();

// Display total customers, suppliers, quotes, orders, NC
$data['customers_count'] = DB::table('companies')->where('statu_customer', '=', '2')->count();
$data['suppliers_count'] = DB::table('companies')->where('statu_supplier', '=', '2')->count();
$data['quotes_count'] = DB::table('quotes')->count();
$data['orders_count'] = DB::table('orders')->count();
$data['quality_non_conformities_count'] = DB::table('quality_non_conformities')->count();
$data['user_count'] = DB::table('users')->count();

$all_count = DB::table('users')->selectRaw("'user_count' as type, count(*) as count")
->unionAll(DB::table('companies')->selectRaw("'customers_count' as type, count(*) as count")->where('statu_customer', '=', '2'))
->unionAll(DB::table('companies')->selectRaw("'suppliers_count' as type, count(*) as count")->where('statu_supplier', '=', '2'))
->unionAll(DB::table('quotes')->selectRaw("'quotes_count' as type, count(*) as count"))
->unionAll(DB::table('orders')->selectRaw("'orders_count' as type, count(*) as count"))
->unionAll(DB::table('quality_non_conformities')->selectRaw("'quality_non_conformities_count' as type, count(*) as count"))
->get();
$data = $all_count->reduce(function($data, $count) {
$data[$count->type] = $count->count;
return $data;
}, []);

$Announcement = Announcements::latest()->first();

//Estimated Budgets data for chart
Expand Down

0 comments on commit 89598f8

Please sign in to comment.