diff --git a/routes/web.php b/routes/web.php index e1c9ea3e..07ea1436 100644 --- a/routes/web.php +++ b/routes/web.php @@ -22,23 +22,26 @@ Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm Route::post('password/reset', 'Auth\ResetPasswordController@postReset')->name('password.reset'); Route::get('/report/x1', function(){ - $this->middleware('role:admin'); - $bookings = Booking::where('admin_status', '>=', 3)->where('term', 'like', 'x1_%')->where('is_cancel', false)->where('user_id', '!=', 1)->get(); - $months = $bookings->groupBy(function($item) { - return $item->created_at->format('Y-m'); - }); - - foreach($months as $month => $bookings){ - echo "

".Carbon::parse($month)->format('m-Y').": ".$bookings->sum('bia')." MYR

"; - $days = $bookings->groupBy(function($item){ - return $item->created_at->format('Y-m-d'); + if($this->middleware('role:admin')){ + $bookings = Booking::where('admin_status', '>=', 3)->where('term', 'like', 'x1_%')->where('is_cancel', false)->where('user_id', '!=', 1)->get(); + $months = $bookings->groupBy(function($item) { + return $item->created_at->format('Y-m'); }); - foreach($days as $day => $bookings ){ - echo "

".Carbon::parse($day)->format('d-m-Y').": ".$bookings->sum('bia')." MYR

"; - } + foreach($months as $month => $bookings){ + echo "

".Carbon::parse($month)->format('m-Y').": ".$bookings->sum('bia')." MYR

"; + $days = $bookings->groupBy(function($item){ + return $item->created_at->format('Y-m-d'); + }); + foreach($days as $day => $bookings ){ + echo "

".Carbon::parse($day)->format('d-m-Y').": ".$bookings->sum('bia')." MYR

"; + } + + } + } else { + return redirect('/'); } });