Merge pull request #8 from LailaWulandarii/development

Development update validation rule and message
This commit is contained in:
Laila Wulandari 2026-02-14 13:56:57 +07:00 committed by GitHub
commit 9e934a268b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 69 additions and 92 deletions

View File

@ -21,52 +21,4 @@ public function index()
$pesananFoto = BookingFoto::where('status_booking', 'menunggu_verifikasi')->latest()->get();
return view('admin.beranda.index', compact('stat', 'buketToday', 'fotoToday', 'pesananBuket', 'pesananFoto'));
}
// public function index()
// {
// $now = Carbon::now();
// $lastMonth = Carbon::now()->subMonth();
// $today = Carbon::today();
// $getGrowth = function ($current, $previous) {
// if ($previous <= 0) return $current > 0 ? 100 : 0;
// return round((($current - $previous) / $previous) * 100, 1);
// };
// $currPendapatan = TransaksiBuket::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_transaksi', 'diterima')->sum('total_bayar') +
// BookingFoto::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_booking', 'diterima')->sum('total_bayar');
// $currMasuk = TransaksiBuket::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->count() +
// BookingFoto::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->count();
// $currSelesai = TransaksiBuket::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_transaksi', 'selesai')->count() +
// BookingFoto::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_booking', 'selesai')->count();
// $currBatal = TransaksiBuket::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_transaksi', 'ditolak')->count() +
// BookingFoto::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_booking', 'ditolak')->count();
// $prevPendapatan = TransaksiBuket::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_transaksi', 'diterima')->sum('total_bayar') +
// BookingFoto::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_booking', 'diterima')->sum('total_bayar');
// $prevMasuk = TransaksiBuket::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->count() +
// BookingFoto::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->count();
// $prevSelesai = TransaksiBuket::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_transaksi', 'selesai')->count() +
// BookingFoto::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_booking', 'selesai')->count();
// $prevBatal = TransaksiBuket::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_transaksi', 'ditolak')->count() +
// BookingFoto::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_booking', 'ditolak')->count();
// $stat = [
// 'pendapatan' => $currPendapatan,
// 'pendapatan_grow' => $getGrowth($currPendapatan, $prevPendapatan),
// 'masuk_count' => $currMasuk,
// 'masuk_grow' => $getGrowth($currMasuk, $prevMasuk),
// 'selesai_count' => $currSelesai,
// 'selesai_grow' => $getGrowth($currSelesai, $prevSelesai),
// 'batal_count' => $currBatal,
// 'batal_grow' => $getGrowth($currBatal, $prevBatal),
// ];
// $buketToday = TransaksiBuket::with(['pelanggan', 'buket'])->whereDate('tgl_ambil', $today)->where('status_transaksi', 'diterima')->get();
// $fotoToday = BookingFoto::with(['pelanggan', 'paketFoto'])->whereDate('tgl_booking', $today)->where('status_booking', 'diterima')->orderBy('jam_mulai', 'asc')->get();
// $pesananBuket = TransaksiBuket::with(['pelanggan', 'buket'])->where('status_transaksi', 'menunggu_verifikasi')->latest()->get();
// $pesananFoto = BookingFoto::with(['pelanggan', 'paketFoto'])->where('status_booking', 'menunggu_verifikasi')->latest()->get();
// return view('admin.beranda.index', compact('stat', 'buketToday', 'fotoToday', 'pesananBuket', 'pesananFoto'));
// }
}

View File

@ -50,6 +50,6 @@ public function destroy(string $id)
Storage::disk('public')->delete($buket->foto);
}
$buket->delete();
return redirect()->back()->with('success', 'Produk dan foto berhasil dihapus permanen!');
return redirect()->back()->with('success', 'Produk buket berhasil dihapus permanen!');
}
}

View File

@ -16,7 +16,7 @@ public function authorize(): bool
public function rules(): array
{
return [
'nama' => 'required|string|min:3|max:100||regex:/^[a-zA-Z0-9\s\.,:"-]+$/',
'nama' => 'required|string|min:3|max:100|regex:/^[a-zA-Z0-9\s\.\:\(\)\"\-\,]+$/',
'harga' => 'required|numeric|min:0',
];
}
@ -24,12 +24,12 @@ public function rules(): array
public function messages(): array
{
return [
'required' => 'Kolom :attribute wajib diisi.',
'required' => ':attribute wajib diisi.',
'numeric' => ':attribute harus berupa angka.',
'string' => 'Input :attribute harus berupa teks valid.',
'regex' => ':attribute hanya boleh berisi huruf, angka, spasi, titik, koma, tanda hubung dan tanda petik dua.',
'min' => ':attribute minimal harus :min karakter/nilai.',
'max' => ':attribute melebihi batas maksimal :max karakter.',
'string' => ':attribute harus berupa teks valid.',
'regex' => ':attribute hanya boleh berisi huruf, angka, spasi, titik, koma, titik dua, tanda kurung, tanda hubung, dan tanda petik dua.',
'min' => ':attribute terlalu pendek, minimal :min karakter.',
'max' => ':attribute terlalu panjang, maksimal :max karakter.',
];
}

View File

@ -32,18 +32,18 @@ public function rules(): array
public function messages(): array
{
return [
'required' => 'Kolom :attribute wajib diisi.',
'required' => ':attribute wajib diisi.',
'numeric' => ':attribute harus berupa angka.',
'string' => ':attribute harus berupa teks valid.',
'unique' => ':attribute sudah terdaftar di sistem, gunakan yang lain.',
'min' => ':attribute minimal harus berisi :min karakter.',
'max' => ':attribute maksimal hanya boleh :max karakter.',
'numeric' => ':attribute harus berupa angka.',
'min' => ':attribute terlalu pendek, minimal :min karakter.',
'max' => ':attribute terlalu panjang, maksimal :max karakter.',
'digits_between' => ':attribute harus berjumlah antara :min sampai :max digit.',
'email' => 'Format :attribute tidak valid.',
'regex' => ':attribute hanya boleh berisi huruf, angka, spasi, titik, koma, tanda hubung dan tanda petik dua.',
'in' => ':attribute yang dipilih tidak sesuai pilihan yang tersedia.',
'nama.regex' => 'Nama hanya boleh berisi huruf dan spasi.',
'username.alpha_num' => 'Username hanya boleh berisi huruf dan angka.',
'alamat.regex' => 'Alamat hanya boleh berisi huruf, angka, spasi, titik, koma, tanda hubung, dan tanda petik dua.',
'alamat.regex' => 'Alamat hanya boleh berisi huruf, angka, spasi, titik, koma, titik dua, tanda hubung, tanda kurung, garis miring, dan tanda petik dua.',
];
}

View File

@ -18,12 +18,12 @@ public function rules(): array
{
return [
//tmbah requirement
'nama' => 'required|string|min:3|max:100|regex:/^[a-zA-Z0-9\s\.,:"-]+$/',
'nama' => 'required|string|min:3|max:100|regex:/^[a-zA-Z0-9\s\.\:\(\)\"\-\,]+$/',
'ukuran' => 'required|in:S,M,L',
'kategori' => 'required|in:single,fresh,premium_fresh,artificial',
'harga' => 'required|numeric|min:0',
'request_khusus' => 'required|string|min:3|max:100|regex:/^[a-zA-Z0-9\s\.,:"-]+$/',
'deskripsi' => 'required|string|min:3|min:100|regex:/^[a-zA-Z0-9\s\.,:"-]+$/',
'request_khusus' => 'required|string|min:3|max:100|regex:/^[a-zA-Z0-9\s\.\:\(\)\"\-\,]+$/',
'deskripsi' => 'required|string|min:3|min:170|regex:/^[a-zA-Z0-9\s\.\:\(\)\"\-\,]+$/',
'foto' => $this->isMethod('post')
? 'required|image|mimes:jpeg,png,jpg|max:2048'
: 'nullable|image|mimes:jpeg,png,jpg|max:2048',
@ -33,12 +33,13 @@ public function rules(): array
public function messages(): array
{
return [
'required' => 'Kolom :attribute tidak boleh kosong.',
'string' => 'Input :attribute harus berupa teks valid.',
'min' => ':attribute terlalu pendek, minimal harus :min karakter.',
'max' => ':attribute melebihi batas, maksimal :max karakter/KB.',
'in' => 'Pilihan :attribute tidak sesuai dengan data yang tersedia.',
'required' => ':attribute wajib diisi.',
'numeric' => ':attribute harus berupa angka.',
'string' => ':attribute harus berupa teks valid.',
'min' => ':attribute terlalu pendek, minimal :min karakter.',
'max' => ':attribute terlalu panjang, maksimal :max karakter.',
'in' => 'Pilihan :attribute tidak sesuai dengan data yang tersedia.',
'regex' => ':attribute hanya boleh berisi huruf, angka, spasi, titik, koma, titik dua, tanda hubung, tanda kurung, garis miring, dan tanda petik dua.',
'image' => ':attribute harus berupa file gambar (foto).',
'mimes' => 'Format :attribute tidak didukung. Gunakan format: jpeg, png, atau jpg.',
'foto.max' => 'Ukuran :attribute terlalu besar, maksimal adalah 2MB.',

View File

@ -16,10 +16,10 @@ public function authorize(): bool
public function rules(): array
{
return [
'nama' => 'required|string|min:3|max:100|regex:/^[a-zA-Z0-9\s\.,:"-]+$/',
'nama' => 'required|string|min:3|max:50|regex:/^[a-zA-Z0-9\s\.\:\(\)\"\-\,]+$/',
'harga' => 'required|numeric|min:0',
'durasi' => 'required|integer|min:0',
'deskripsi' => 'required|string|min:10|regex:/^[a-zA-Z0-9\s\.,:"-]+$/',
'deskripsi' => 'required|string|min:3|max:170|regex:/^[a-zA-Z0-9\s\.\:\(\)\"\-\,]+$/',
'foto' => $this->isMethod('post')
? 'required|image|mimes:jpeg,png,jpg|max:2048'
: 'nullable|image|mimes:jpeg,png,jpg|max:2048',
@ -29,12 +29,14 @@ public function rules(): array
public function messages(): array
{
return [
'required' => 'Kolom :attribute wajib diisi.',
'string' => 'Input :attribute harus berupa teks valid.',
'required' => ':attribute wajib diisi.',
'numeric' => ':attribute harus berupa angka.',
'string' => ':attribute harus berupa teks valid.',
'integer' => 'Input :attribute harus berupa angka valid.',
'numeric' => ':attribute harus berupa angka.',
'min' => ':attribute minimal harus :min karakter/nilai.',
'max' => ':attribute melebihi batas, maksimal :max karakter/KB.',
'regex' => ':attribute hanya boleh berisi huruf, angka, spasi, titik, koma, titik dua, tanda hubung, tanda kurung, garis miring, dan tanda petik dua.',
'min' => ':attribute terlalu pendek, minimal :min karakter.',
'max' => ':attribute terlalu panjang, maksimal :max karakter.',
'image' => ':attribute harus berupa file gambar (foto).',
'mimes' => 'Format :attribute tidak didukung (jpeg, png, jpg).',
'foto.max' => 'Ukuran :attribute maksimal 2MB.',

View File

@ -3,6 +3,7 @@
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;
class PasswordRequest extends FormRequest
{
@ -17,7 +18,8 @@ public function authorize(): bool
public function rules(): array
{
return [
'password' => 'required|min:8|confirmed',
'password' => 'required|min:8|max:15|confirmed',
'password_confirmation' => 'required|same:password',
];
}
@ -25,8 +27,24 @@ public function messages(): array
{
return [
'required' => 'Kata sandi baru wajib diisi.',
'min' => 'Kata sandi minimal :min karakter.',
'min' => 'Kata sandi terlalu pendek, minimal :min karakter.',
'confirmed' => 'Konfirmasi kata sandi tidak cocok.',
'password_confirmation.required' => 'Konfirmasi kata sandi wajib diisi.',
'password_confirmation.same' => 'Konfirmasi kata sandi tidak cocok.'
];
}
public function withValidator(Validator $validator)
{
$validator->after(function ($validator) {
if ($validator->errors()->has('password')) {
$messages = $validator->errors()->get('password');
foreach ($messages as $message) {
// Jika pesan error berisi tentang konfirmasi, tambahkan ke field konfirmasi
if ($message == 'Konfirmasi kata sandi tidak cocok.') {
$validator->errors()->add('password_confirmation', $message);
}
}
}
});
}
}

View File

@ -20,24 +20,24 @@ public function rules(): array
$userId = Auth::id();
//tambah validasi
return [
'nama' => 'required|string|min:3|max:100|regex:/^[a-zA-Z\s]+$/',
'username' => 'required|string|alpha_num|max:10|unique:users,username,' . $userId . ',id_user',
'nama' => 'required|string|min:3|max:30|regex:/^[a-zA-Z\s]+$/',
'username' => 'required|string|alpha_num|min:5|max:10|unique:users,username,' . $userId . ',id_user',
'email' => 'required|email|unique:users,email,' . $userId . ',id_user',
'no_wa' => 'nullable|numeric|digits_between:10,15',
'alamat' => 'nullable|string|max:200|regex:/^[a-zA-Z0-9\s\.,:"-]+$/',
'alamat' => 'nullable|string|min:10|max:150|regex:/^[a-zA-Z0-9\s\.\,\/\-\(\)]+$/',
];
}
public function messages(): array
{
return [
'required' => 'Kolom :attribute wajib diisi.',
'required' => ':attribute wajib diisi.',
'unique' => ':attribute sudah digunakan.',
'numeric' => ':attribute harus berupa angka.',
'email' => 'Format :attribute tidak valid.',
'digits_between' => ':attribute harus berjumlah antara 10 sampai 15 digit.',
'min' => ':attribute minimal harus berisi :min karakter.',
'max' => ':attribute maksimal hanya boleh :max karakter.',
'min' => ':attribute terlalu pendek, minimal :min karakter.',
'max' => ':attribute terlalu panjang, maksimal :max karakter.',
'nama.regex' => 'Nama hanya boleh berisi huruf dan spasi.',
'username.alpha_num' => 'Username hanya boleh berisi huruf dan angka.',
'alamat.regex' => 'Alamat hanya boleh berisi huruf, angka, spasi, titik, koma, tanda hubung, dan tanda petik dua.',

View File

@ -28,9 +28,9 @@ public function messages(): array
return [
'required' => 'Kolom :attribute wajib diisi.',
'image' => ':attribute harus berupa file gambar.',
'max' => 'Ukuran :attribute maksimal adalah 2MB.',
'min' => ':attribute terlalu pendek, minimal :min karakter.',
'max' => ':attribute terlalu panjang, maksimal :max karakter.',
'string' => 'Input :attribute harus berupa teks valid.',
'min' => ':attribute terlalu pendek, minimal :min karakter.',
'numeric' => ':attribute harus berupa angka.',
'digits_between' => ':attribute harus antara :min sampai :max digit.',
'date' => 'Format tanggal pada :attribute tidak valid.',

View File

@ -14,9 +14,8 @@ public function authorize(): bool
public function rules(): array
{
return [
'id_buket' => 'required|exists:bukets,id_buket', // Tambahan validasi keamanan
//tambahan validasi untuk teks aja
'nama' => 'required|string|min:3|max:100|regex:/^[a-zA-Z\s]+$/',
'id_buket' => 'required|exists:bukets,id_buket',
'nama' => 'required|string|min:3|max:30|regex:/^[a-zA-Z\s]+$/',
'no_wa' => 'required|numeric|digits_between:10,15',
'tgl_ambil' => 'required|date|after_or_equal:today',
'waktu_ambil' => [
@ -26,16 +25,16 @@ public function rules(): array
'before_or_equal:21:00',
],
'bukti_bayar' => 'required|image|mimes:jpeg,png,jpg|max:2048',
'request_khusus' => 'nullable|string|max:250',
'ucapan' => 'nullable|string|max:100',
'request_khusus' => 'nullable|string|max:150',
'ucapan' => 'nullable|string|max:150',
];
}
public function messages(): array
{
return [
'required' => 'Kolom :attribute wajib diisi.',
'string' => 'Input :attribute harus berupa teks valid.',
'required' => ':attribute harus diisi.',
'string' => ':attribute harus berupa teks valid.',
'min' => ':attribute terlalu pendek, minimal :min karakter.',
'max' => ':attribute terlalu panjang, maksimal :max karakter.',
'numeric' => ':attribute harus berupa angka.',
@ -48,6 +47,7 @@ public function messages(): array
'bukti_bayar.max' => 'Ukuran :attribute maksimal adalah 2MB.',
'waktu_ambil.after_or_equal' => 'Jam operasional kami mulai pukul 09:00.',
'waktu_ambil.before_or_equal' => 'Jam operasional kami berakhir pukul 21:00.',
];
}

View File

@ -183,6 +183,10 @@ class="form-control @error('password', 'updatePassword') is-invalid @enderror"
id="iconKonfirm"></i>
</span>
</div>
@if ($errors->updatePassword->has('password_confirmation'))
<small
class="text-danger">{{ $errors->updatePassword->first('password_confirmation') }}</small>
@endif
</div>
</div>
</div>