-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d938794
commit 985d8cb
Showing
13 changed files
with
462 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Enum\Role; | ||
use App\Http\Requests\StoreTeacherRequest; | ||
use App\Http\Requests\UpdateTeacherRequest; | ||
use App\Models\User; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\View\View; | ||
use Yajra\DataTables\DataTables; | ||
|
||
class TeacherController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
*/ | ||
public function index(Request $request): View|JsonResponse | ||
{ | ||
if ($request->ajax()) { | ||
return DataTables::of(User::role(Role::TEACHER)) | ||
->addColumn('action', function ($row) { | ||
return '<div class="dropdown"> | ||
<button type="button" | ||
class="btn p-0 dropdown-toggle hide-arrow" | ||
data-bs-toggle="dropdown"> | ||
<i class="bx bx-dots-vertical-rounded"></i> | ||
</button> | ||
<div class="dropdown-menu"> | ||
<a class="dropdown-item" href="'.route('teacher.edit', $row).'"><i class="bx bx-edit-alt me-1"></i>'.__('label.edit').'</a> | ||
<form action="'.route('teacher.destroy', $row).'" method="post" onsubmit="confirmSubmit(event, this)"> | ||
<input type="hidden" name="_method" value="DELETE"> | ||
<input type="hidden" name="_token" value="'.csrf_token().'" /> | ||
<button class="dropdown-item" type="submit"><i class="bx bx-trash me-1"></i>'.__('label.delete').'</button> | ||
</form> | ||
</div> | ||
</div>'; | ||
}) | ||
->editColumn('gender', fn ($row) => __('label.'.$row->gender)) | ||
->rawColumns(['action']) | ||
->make(); | ||
} | ||
|
||
return view('pages.teacher.index'); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
*/ | ||
public function create(): View | ||
{ | ||
return view('pages.teacher.create'); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
*/ | ||
public function store(StoreTeacherRequest $request): RedirectResponse | ||
{ | ||
try { | ||
$data = $request->validated(); | ||
$data['role'] = Role::TEACHER; | ||
$data['password'] = bcrypt('password'); | ||
|
||
User::create($data); | ||
|
||
return redirect()->route('teacher.index')->with('notification', $this->successNotification('notification.success_create', 'menu.teacher')); | ||
} catch (\Throwable $throwable) { | ||
Log::error($throwable->getMessage()); | ||
|
||
return back()->with('notification', $this->successNotification('notification.fail_create', 'menu.teacher')); | ||
} | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
*/ | ||
public function show(User $teacher): View | ||
{ | ||
return view('pages.teacher.show', [ | ||
'teacher' => $teacher, | ||
]); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
*/ | ||
public function edit(User $teacher): View | ||
{ | ||
return view('pages.teacher.edit', [ | ||
'teacher' => $teacher, | ||
]); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
*/ | ||
public function update(UpdateTeacherRequest $request, User $teacher): RedirectResponse | ||
{ | ||
try { | ||
$teacher->update($request->validated()); | ||
|
||
return back()->with('notification', $this->successNotification('notification.success_update', 'menu.teacher')); | ||
} catch (\Throwable $throwable) { | ||
Log::error($throwable->getMessage()); | ||
|
||
return back()->with('notification', $this->successNotification('notification.fail_update', 'menu.teacher')); | ||
} | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
*/ | ||
public function destroy(User $teacher): RedirectResponse | ||
{ | ||
try { | ||
$teacher->delete(); | ||
|
||
return back()->with('notification', $this->successNotification('notification.success_delete', 'menu.teacher')); | ||
} catch (\Throwable $throwable) { | ||
Log::error($throwable->getMessage()); | ||
|
||
return back()->with('notification', $this->successNotification('notification.fail_delete', 'menu.teacher')); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\Enum\Role; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
|
||
class StoreTeacherRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return auth()->user()->isRole(Role::OWNER) || auth()->user()->isRole(Role::HEADMASTER) || auth()->user()->isRole(Role::ADMINISTRATOR); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, ValidationRule|array|string> | ||
*/ | ||
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'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\Enum\Role; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
|
||
class UpdateTeacherRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return auth()->user()->isRole(Role::OWNER) || auth()->user()->isRole(Role::HEADMASTER) || auth()->user()->isRole(Role::ADMINISTRATOR); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, ValidationRule|array|string> | ||
*/ | ||
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'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ | |
'profile' => 'Profil', | ||
'change_password' => 'Ganti Password', | ||
'locale' => 'Bahasa', | ||
'teacher' => 'Pengajar', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,63 @@ | ||
{ | ||
"menu": [ | ||
{ | ||
"url": "dashboard", | ||
"name": "menu.dashboard", | ||
"icon": "menu-icon tf-icons bx bx-home-circle", | ||
"slug": "dashboard" | ||
}, | ||
{ | ||
"name": "menu.account", | ||
"icon": "menu-icon tf-icons bx bx bx-user", | ||
"slug": "account.*", | ||
"submenu": [ | ||
"menu": [ | ||
{ | ||
"url": "account.profile.edit", | ||
"name": "menu.profile", | ||
"slug": "account.profile.edit" | ||
"url": "dashboard", | ||
"name": "menu.dashboard", | ||
"icon": "menu-icon tf-icons bx bx-home-circle", | ||
"slug": "dashboard", | ||
"role": [ | ||
"owner", | ||
"headmaster", | ||
"admin", | ||
"student_guardian" | ||
] | ||
}, | ||
{ | ||
"url": "account.password.edit", | ||
"name": "menu.change_password", | ||
"slug": "account.password.edit" | ||
"url": "teacher.index", | ||
"name": "menu.teacher", | ||
"icon": "menu-icon tf-icons bx bx-user-voice", | ||
"slug": "teacher.*", | ||
"role": [ | ||
"owner", | ||
"headmaster", | ||
"admin", | ||
"student_guardian" | ||
] | ||
}, | ||
{ | ||
"name": "menu.account", | ||
"icon": "menu-icon tf-icons bx bx bx-user", | ||
"slug": "account.*", | ||
"role": [ | ||
"owner", | ||
"headmaster", | ||
"admin", | ||
"student_guardian" | ||
], | ||
"submenu": [ | ||
{ | ||
"url": "account.profile.edit", | ||
"name": "menu.profile", | ||
"slug": "account.profile.edit", | ||
"role": [ | ||
"owner", | ||
"headmaster", | ||
"admin", | ||
"student_guardian" | ||
] | ||
}, | ||
{ | ||
"url": "account.password.edit", | ||
"name": "menu.change_password", | ||
"slug": "account.password.edit", | ||
"role": [ | ||
"owner", | ||
"headmaster", | ||
"admin", | ||
"student_guardian" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
] | ||
} |
Oops, something went wrong.