diff --git a/app/Http/Controllers/StudentGuardianController.php b/app/Http/Controllers/StudentGuardianController.php new file mode 100644 index 0000000..9b7da83 --- /dev/null +++ b/app/Http/Controllers/StudentGuardianController.php @@ -0,0 +1,148 @@ +ajax()) { + return DataTables::eloquent(User::role(Role::STUDENT_GUARDIAN)) + ->addColumn('action', function ($row) { + return ''; + }) + ->editColumn('image', fn ($row) => 'user-avatar') + ->editColumn('gender', fn ($row) => __('label.'.$row->gender)) + ->filterColumn('gender', fn ($query, $keyword) => $query->where('gender', $keyword)) + ->rawColumns(['action', 'image']) + ->toJson(); + } + + return view('pages.student-guardian.index'); + } + + /** + * Show the form for creating a new resource. + */ + public function create(): View + { + return view('pages.student-guardian.create'); + } + + /** + * Store a newly created resource in storage. + */ + public function store(StoreStudentGuardianRequest $request): RedirectResponse + { + try { + $data = $request->validated(); + $data['role'] = Role::STUDENT_GUARDIAN; + $data['password'] = bcrypt('password'); + + if ($request->hasFile('image')) { + $data['image'] = time().random_int(0, PHP_INT_MAX).'.'.$request->file('image')->extension(); + Storage::putFileAs('public', $request->file('image'), $data['image']); + } + + User::create($data); + + return redirect()->route('student-guardian.index')->with('notification', $this->successNotification('notification.success_create', 'menu.student_guardian')); + } catch (\Throwable $throwable) { + Log::error($throwable->getMessage()); + + return back()->with('notification', $this->successNotification('notification.fail_create', 'menu.student_guardian')); + } + } + + /** + * Display the specified resource. + */ + public function show(User $student_guardian): View + { + return view('pages.student-guardian.show', [ + 'guardian' => $student_guardian, + ]); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(User $student_guardian): View + { + return view('pages.student-guardian.edit', [ + 'guardian' => $student_guardian, + ]); + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateStudentGuardianRequest $request, User $student_guardian): RedirectResponse + { + try { + $data = $request->validated(); + + if ($request->hasFile('image')) { + if ($student_guardian->image) { + Storage::delete("public/{$student_guardian->image}"); + } + + $data['image'] = time().random_int(0, PHP_INT_MAX).'.'.$request->file('image')->extension(); + Storage::putFileAs('public', $request->file('image'), $data['image']); + } + + $student_guardian->update($data); + + return back()->with('notification', $this->successNotification('notification.success_update', 'menu.student_guardian')); + } catch (\Throwable $throwable) { + Log::error($throwable->getMessage()); + + return back()->with('notification', $this->successNotification('notification.fail_update', 'menu.student_guardian')); + } + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(User $student_guardian): RedirectResponse + { + try { + $student_guardian->delete(); + + return back()->with('notification', $this->successNotification('notification.success_delete', 'menu.student_guardian')); + } catch (\Throwable $throwable) { + Log::error($throwable->getMessage()); + + return back()->with('notification', $this->successNotification('notification.fail_delete', 'menu.student_guardian')); + } + } +} diff --git a/app/Http/Requests/StoreStudentGuardianRequest.php b/app/Http/Requests/StoreStudentGuardianRequest.php new file mode 100644 index 0000000..728b7a5 --- /dev/null +++ b/app/Http/Requests/StoreStudentGuardianRequest.php @@ -0,0 +1,50 @@ +user()->isRole(Role::OWNER) || auth()->user()->isRole(Role::HEADMASTER); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + 'name' => ['required'], + 'email' => ['required', 'email', Rule::unique('users', 'email')], + 'image' => ['nullable', 'image', 'max:2048'], + 'phone' => ['required'], + 'address' => ['nullable'], + 'marital_status' => ['nullable'], + 'gender' => ['required'], + ]; + } + + public function attributes(): array + { + return [ + 'name' => __('field.name'), + 'email' => __('field.email'), + 'image' => __('field.image'), + 'phone' => __('field.phone'), + 'address' => __('field.address'), + 'marital_status' => __('field.marital_status'), + 'gender' => __('field.gender'), + ]; + } +} diff --git a/app/Http/Requests/UpdateStudentGuardianRequest.php b/app/Http/Requests/UpdateStudentGuardianRequest.php new file mode 100644 index 0000000..8b67870 --- /dev/null +++ b/app/Http/Requests/UpdateStudentGuardianRequest.php @@ -0,0 +1,50 @@ +user()->isRole(Role::OWNER) || auth()->user()->isRole(Role::HEADMASTER); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + 'name' => ['required'], + 'email' => ['required', 'email', Rule::unique('users', 'email')->ignore($this->id)], + 'image' => ['nullable', 'image', 'max:2048'], + 'phone' => ['required'], + 'address' => ['nullable'], + 'marital_status' => ['nullable'], + 'gender' => ['required'], + ]; + } + + public function attributes(): array + { + return [ + 'name' => __('field.name'), + 'email' => __('field.email'), + 'image' => __('field.image'), + 'phone' => __('field.phone'), + 'address' => __('field.address'), + 'marital_status' => __('field.marital_status'), + 'gender' => __('field.gender'), + ]; + } +} diff --git a/lang/en/menu.php b/lang/en/menu.php index 379340c..d64213e 100644 --- a/lang/en/menu.php +++ b/lang/en/menu.php @@ -20,4 +20,5 @@ 'user_management' => 'User Management', 'setting' => 'Setting', 'administrator' => 'Administrator', + 'student_guardian' => 'Student Guardian', ]; diff --git a/lang/id/menu.php b/lang/id/menu.php index 09aa71a..54520f5 100644 --- a/lang/id/menu.php +++ b/lang/id/menu.php @@ -20,4 +20,5 @@ 'user_management' => 'Pengelolaan Pengguna', 'setting' => 'Pengaturan', 'administrator' => 'Admin', + 'student_guardian' => 'Wali Santri', ]; diff --git a/resources/menu/verticalMenu.json b/resources/menu/verticalMenu.json index f4222c4..5fbdca3 100644 --- a/resources/menu/verticalMenu.json +++ b/resources/menu/verticalMenu.json @@ -42,6 +42,17 @@ "administrator" ] }, + { + "url": "student-guardian.index", + "name": "menu.student_guardian", + "icon": "menu-icon tf-icons bx bx-group", + "slug": "student-guardian.*", + "role": [ + "owner", + "headmaster", + "administrator" + ] + }, { "menuHeader": "menu.setting", "role": [ diff --git a/resources/views/pages/student-guardian/create.blade.php b/resources/views/pages/student-guardian/create.blade.php new file mode 100644 index 0000000..bd71d93 --- /dev/null +++ b/resources/views/pages/student-guardian/create.blade.php @@ -0,0 +1,100 @@ +@extends('layouts.dashboard') + +@section('content') + + +
+
+ @csrf +
+
+ + user-avatar + +
+ + + + {{ __('label.allowed_image_upload') }} +
+
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + +
+
+
+
+ +@endsection + +@push('script') + +@endpush diff --git a/resources/views/pages/student-guardian/edit.blade.php b/resources/views/pages/student-guardian/edit.blade.php new file mode 100644 index 0000000..516508c --- /dev/null +++ b/resources/views/pages/student-guardian/edit.blade.php @@ -0,0 +1,102 @@ +@extends('layouts.dashboard') + +@section('content') + + +
+
+
+
+ + user-avatar + +
+ + + + {{ __('label.allowed_image_upload') }} +
+
+
+
+
+ @csrf + @method('PUT') + +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + +
+
+
+
+ +@endsection + +@push('script') + +@endpush diff --git a/resources/views/pages/student-guardian/index.blade.php b/resources/views/pages/student-guardian/index.blade.php new file mode 100644 index 0000000..4fcbbd5 --- /dev/null +++ b/resources/views/pages/student-guardian/index.blade.php @@ -0,0 +1,65 @@ +@extends('layouts.dashboard') + +@section('content') +
+

{{ __('menu.student_guardian') }}

+
+ + + {{ __('menu.student_guardian') }} + +
+
+ +
+
+ + + + + + + + + + + + + +
{{ __('field.name') }}{{ __('field.gender') }}{{ __('field.email') }}{{ __('field.phone') }}
+
+
+@endsection + +@push('style') + +@endpush + +@push('script') + + +@endpush diff --git a/routes/web.php b/routes/web.php index d05bb97..28e302e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,6 +19,7 @@ Route::resource('administrator', \App\Http\Controllers\AdministratorController::class); Route::resource('teacher', \App\Http\Controllers\TeacherController::class); + Route::resource('student-guardian', \App\Http\Controllers\StudentGuardianController::class); Route::as('account.')->group(function () { Route::get('/account/profile', [ProfileController::class, 'edit'])->name('profile.edit');