schoolPrefix = request()->query( 'school_prefix', null ); } public function filterStudents() { if ( ! empty( $this->schoolPrefix ) ) { // $this->students = User::where('school_no', $_GET['school_no'])->get(); $this->students = User::where( 'school_no', 'like', $this->schoolPrefix . '%' )->get(); } else { $this->students = User::all(); } } public function deleteStudent( $schoolNo ) { // 刪除學生 User::where( 'school_no', $schoolNo )->delete(); // 重新載入學生資料,確保前端更新 $this->filterStudents(); } public function render() { // get school prefix from all school_no[0:5] $this->allSchoolPrefixs = User::all()->map( function ($user) { return substr( $user->school_no, 0, 5 ); } )->unique(); $this->filterStudents(); return view( 'livewire.students-list' )->layout( 'components.admin-layout' ); } }