From 2608d73a8f00c9baf1c433515fd071e3188ccb56 Mon Sep 17 00:00:00 2001 From: Alfian <112760996+alfian8752@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:10:30 +0700 Subject: [PATCH] master rfid --- .../Interfaces/ModelHasRfidInterface.php | 1 + .../Repositories/ModelHasRfidRepository.php | 13 +++++++-- app/Helpers/helpers.php | 27 +++++++++++++++++ .../Controllers/ModelHasRfidController.php | 4 +-- .../Controllers/SchoolDashboardController.php | 29 +++++++++++++++---- composer.json | 6 +++- .../pages/settings/information.blade.php | 19 ++---------- routes/role/school.php | 12 ++------ 8 files changed, 74 insertions(+), 37 deletions(-) create mode 100644 app/Helpers/helpers.php diff --git a/app/Contracts/Interfaces/ModelHasRfidInterface.php b/app/Contracts/Interfaces/ModelHasRfidInterface.php index 79c0a542..f906f98e 100644 --- a/app/Contracts/Interfaces/ModelHasRfidInterface.php +++ b/app/Contracts/Interfaces/ModelHasRfidInterface.php @@ -15,6 +15,7 @@ interface ModelHasRfidInterface extends GetInterface, StoreInterface, UpdateInte public function exists(mixed $rfid): mixed; public function activeRfid(): mixed; + public function masterRfid(): mixed; public function nonActiveRfid(): mixed; public function whereSchool($id): mixed; public function whereNotNull(mixed $column):mixed; diff --git a/app/Contracts/Repositories/ModelHasRfidRepository.php b/app/Contracts/Repositories/ModelHasRfidRepository.php index b156fb0c..0a216cf9 100644 --- a/app/Contracts/Repositories/ModelHasRfidRepository.php +++ b/app/Contracts/Repositories/ModelHasRfidRepository.php @@ -31,6 +31,13 @@ public function nonActiveRfid(): mixed ->get(); } + public function masterRfid(): mixed + { + return $this->model->query() + ->where('model_type', 'App\Models\School') + ->get(); + } + public function store(array $data): mixed { return $this->model->query()->create($data); @@ -66,17 +73,17 @@ public function exists(mixed $rfid): mixed return $this->model->query()->where('rfid', $rfid)->exists(); } - public function whereSchool($id): mixed + public function whereSchool($id): mixed { return $this->model->query()->where('school_id', $id)->get(); } - public function whereNotNull(mixed $column):mixed + public function whereNotNull(mixed $column):mixed { return $this->model->query()->whereNotNull($column)->get(); } - public function whereNull(mixed $column):mixed + public function whereNull(mixed $column):mixed { return $this->model->query()->whereNull($column)->get(); } diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php new file mode 100644 index 00000000..ad641bb7 --- /dev/null +++ b/app/Helpers/helpers.php @@ -0,0 +1,27 @@ +user()->school; + } +} + +if (!function_exists('auth_student')) { + function auth_student() + { + return auth()->user()->student; + } +} +if (!function_exists('auth_employee')) { + function auth_employee() + { + return auth()->user()->employee; + } +} +if (!function_exists('auth_user')) { + function auth_user() + { + return auth()->user(); + } +} diff --git a/app/Http/Controllers/ModelHasRfidController.php b/app/Http/Controllers/ModelHasRfidController.php index 69e633f8..f1121bf2 100644 --- a/app/Http/Controllers/ModelHasRfidController.php +++ b/app/Http/Controllers/ModelHasRfidController.php @@ -69,9 +69,9 @@ public function store(StoreModelHasRfidRequest $request) public function storeMaster(StoreModelHasRfidRequest $request) { $exist = $this->service->check($request); - $school = $this->school->whereUserId(auth()->user()->id); + $school = auth_school(); if ($exist) { - $this->modelHasRfid->store(['rfid' => $request->rfid, 'model_type' => 'App\Models\School', 'model_id' => $school->id]); + $this->modelHasRfid->store(['rfid' => $request->rfid, 'model_type' => 'App\Models\School', 'model_id' => $school->id, 'school_id' => auth_school()->id]); return redirect()->back()->with('success', 'Berhasil menambahkan master key'); } else { return redirect()->back()->with('error', 'Kartu tidak valid'); diff --git a/app/Http/Controllers/SchoolDashboardController.php b/app/Http/Controllers/SchoolDashboardController.php index c60b1447..3923a37c 100644 --- a/app/Http/Controllers/SchoolDashboardController.php +++ b/app/Http/Controllers/SchoolDashboardController.php @@ -2,33 +2,50 @@ namespace App\Http\Controllers; +use App\Contracts\Interfaces\ModelHasRfidInterface; use App\Contracts\Interfaces\SchoolInterface; use App\Contracts\Interfaces\SchoolYearInterface; +use App\Http\Requests\StoreModelHasRfidRequest; use App\Models\School; +use App\Services\ModelHasRfidService; use Illuminate\Http\Request; +use PhpParser\Node\Expr\FuncCall; class SchoolDashboardController extends Controller { private SchoolInterface $school; private SchoolYearInterface $schoolYear; + private ModelHasRfidInterface $rfid; - public function __construct(SchoolInterface $school, SchoolYearInterface $schoolYear) { + public function __construct(SchoolInterface $school, SchoolYearInterface $schoolYear, ModelHasRfidInterface $rfid) + { $this->school = $school; $this->schoolYear = $schoolYear; + $this->rfid = $rfid; } - public function index() { + public function index() + { + $classroomCount = + return view('school.pages.dashboard'); + } + + public function show() + { + $rfids = $this->rfid->masterRfid(); $school = $this->school->showWithSlug(auth()->user()->slug); $schoolYear = $this->schoolYear->active($school->id); - return view('school.pages.settings.information', compact('school', 'schoolYear')); + return view('school.pages.settings.information', compact('school', 'schoolYear', 'rfids')); } - public function edit() { + public function edit() + { $school = $this->school->showWithSlug(auth()->user()->slug); return view('school.pages.settings.update-information', compact('school')); } - public function update() { + public function update() + { // } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index 94ef9645..57b81a8f 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,11 @@ "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" - } + }, + "files": [ + "app/Helpers/helpers.php" + ] + }, "autoload-dev": { "psr-4": { diff --git a/resources/views/school/pages/settings/information.blade.php b/resources/views/school/pages/settings/information.blade.php index c798a377..b7ff4577 100644 --- a/resources/views/school/pages/settings/information.blade.php +++ b/resources/views/school/pages/settings/information.blade.php @@ -95,19 +95,14 @@ No - Nama Pengguna - Email RFID - @forelse (range(1,6) as $rfid) + @forelse ($rfids as $rfid) - 1 - Arya Rizki - arya@gmail.com - 12345678 - + {{ $loop->iteration }} + {{ $rfid->rfid }} @empty Belum ada RFID @@ -131,14 +126,6 @@