add validation for masa input

This commit is contained in:
Jagad R R
2025-01-18 15:01:28 +07:00
parent d497fe08a5
commit 4f8384676b
7 changed files with 109 additions and 21 deletions
@@ -34,10 +34,10 @@ class FormUpCountryController extends Controller
$this->checkAuthorization(auth()->user(), ['forms.country.view']);
$role = auth()->user()->getRoleNames()[0];
$forms = FormUpCountry::whereMonth('tanggal', date('m'))
->whereYear('tanggal', date('Y'))
->where('tanggal', '<=', date('Y-m-' . env('CLOSING_DATE')))
->whereRaw('DAY(CURDATE()) <= ' . env('CLOSING_DATE'))
$startDate = date('Y-m-' . env('STARTING_DATE')); // Starting date from .env for the current month
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE'); // Closing date for the next month
$forms = FormUpCountry::whereBetween('tanggal', [$startDate, $closingDateNextMonth])
->orderBy('tanggal', 'desc')
->with(['rayon', 'user'])
->get();
@@ -140,6 +140,16 @@ class FormUpCountryController extends Controller
'bukti_hotel' => ['nullable', 'file', 'max:51200', new FileType(['php', 'exe', 'js', 'sh', 'bat', 'exe', 'sh', 'php', 'vbs'])],
]);
$currentDate = date('Y-m-d');
$startDate = date('Y-m-' . env('STARTING_DATE'));
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
if ($currentDate < $startDate || $currentDate > $closingDateNextMonth) {
return response()->json([
'error' => 'Current date is not within the valid range.'
], 400);
}
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
$region = Region::where('id', $cabang->region_id)->first();
$kategori = Kategori::where('name', 'Up Country')->first();