From fd4363903bfbcbe4617c2a418e60893bf81dd945 Mon Sep 17 00:00:00 2001 From: Krzysztof Rewak Date: Tue, 8 Oct 2024 19:55:01 +0200 Subject: [PATCH] - students multisearch (#164) * - students multisearch * - lintf --- .../Dashboard/GroupStudentController.php | 14 ++++++++++---- app/Models/Group.php | 4 ++++ .../Dashboard/CourseSemester/Student/Index.vue | 13 ++++++++----- resources/js/Pages/Dashboard/Student/Index.vue | 6 +++--- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Dashboard/GroupStudentController.php b/app/Http/Controllers/Dashboard/GroupStudentController.php index 1df3674..feb298f 100644 --- a/app/Http/Controllers/Dashboard/GroupStudentController.php +++ b/app/Http/Controllers/Dashboard/GroupStudentController.php @@ -21,16 +21,22 @@ public function index(Request $request, CourseSemester $course, Group $group): R $students = $group->students() ->paginate() ->withQueryString(); - $availableStudents = $searchText - ? Student::query() + + $availableStudents = match(true) { + $searchText === null => [], + preg_match("/^(\d+\s?)+$/", $searchText) === 1 => Student::query() + ->whereNotIn("id", $group->students->pluck("id")) + ->whereIn("index_number", explode(" ", $searchText)) + ->get(), + default => Student::query() ->whereNotIn("id", $group->students->pluck("id")) ->where( fn(Builder $query): Builder => $query ->where("first_name", "ILIKE", "%$searchText%") ->orWhere("surname", "ILIKE", "%$searchText%") ->orWhere("index_number", "LIKE", "%$searchText%"), - )->get() - : []; + )->get(), + }; return inertia("Dashboard/CourseSemester/Student/Index", [ "course" => CourseSemesterData::fromModel($course), diff --git a/app/Models/Group.php b/app/Models/Group.php index 5d7e747..14b253d 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -5,6 +5,7 @@ namespace Keating\Models; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Concerns\HasUlids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -20,6 +21,9 @@ * @property StudyForm $form * @property Carbon $created_at * @property Carbon $updated_at + * @property-read CourseSemester $course + * @property-read Collection $students + * @property-read Collection $gradeColumns */ class Group extends Model { diff --git a/resources/js/Pages/Dashboard/CourseSemester/Student/Index.vue b/resources/js/Pages/Dashboard/CourseSemester/Student/Index.vue index a9e5a56..cf1d1cd 100644 --- a/resources/js/Pages/Dashboard/CourseSemester/Student/Index.vue +++ b/resources/js/Pages/Dashboard/CourseSemester/Student/Index.vue @@ -75,7 +75,10 @@ watch(form, debounce(() => {
- +
+ + podaj imiona, nazwiska, numery indeksu lub zestawy numerów indeksów oddzielone spacjami +
@@ -93,10 +96,10 @@ watch(form, debounce(() => {