app/Http/Controllers/StudentController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index(Request $request)
    {
        if ($request->isMethod("POST") === false){
            $hasVoChong = $hasNoVoChong = true;
        }
        else{
            $hasVoChong = $request->has('has_vo_chong');
            $hasNoVoChong = $request->has('has_no_vo_chong');
        }
        $numberOfChildren = $request->get('number_of_children') ?? '';
        $query = Student::query();
        if ((!$hasVoChong && $hasNoVoChong) || ($hasVoChong && !$hasNoVoChong) ){
            if(!$hasVoChong && $hasNoVoChong){
                $query->whereNull('information->vo_chong');
            }
            else{
                $query->whereNotNull('information->vo_chong');
            }
        }
        if (ctype_digit($numberOfChildren)) {
            $query->where('information->number_of_children', '=', $numberOfChildren);
        }
        if ($request->has('interest')) {
            $interests = $request->get('interest');
            $query->where(function ($query) use ($interests) {
                foreach($interests as $interest) {
                    $query->orWhereJsonContains('interest', $interest);
                }
            });
        }
        $items = $query->orderBy('id', 'desc')->paginate(5);
        return view('student.index', [
                                        'items' => $items,
                                        'hasVoChong' => $hasVoChong,
                                        'hasNoVoChong' => $hasNoVoChong,
                                        'number_of_children' => $request->get('number_of_children'),
                                        'interest' => $request->get('interest')??[],
                                    ]
        );
    }
public function index ( Request $ request ) { if ( $ request -> isMethod ( " POST " ) === false ) { $ hasVoChong = $ hasNoVoChong = true ; } else { $ hasVoChong = $ request -> has ( 'has_vo_chong' ) ; $ hasNoVoChong = $ request -> has ( 'has_no_vo_chong' ) ; } $ numberOfChildren = $ request -> get ( 'number_of_children' ) ?? '' ; $ query = Student :: query ( ) ; if ( ( ! $ hasVoChong && $ hasNoVoChong ) || ( $ hasVoChong && ! $ hasNoVoChong ) ) { if ( ! $ hasVoChong && $ hasNoVoChong ) { $ query -> whereNull ( 'information->vo_chong' ) ; } else { $ query -> whereNotNull ( 'information->vo_chong' ) ; } } if ( ctype_digit ( $ numberOfChildren ) ) { $ query -> where ( 'information->number_of_children' , '=' , $ numberOfChildren ) ; } if ( $ request -> has ( 'interest' ) ) { $ interests = $ request -> get ( 'interest' ) ; $ query -> where ( function ( $ query ) use ( $ interests ) { foreach ( $ interests as $ interest ) { $ query -> orWhereJsonContains ( 'interest' , $ interest ) ; } } ) ; } $ items = $ query -> orderBy ( 'id' , 'desc' ) -> paginate ( 5 ) ; return view ( 'student.index' , [ 'items' => $ items , 'hasVoChong' => $ hasVoChong , 'hasNoVoChong' => $ hasNoVoChong , 'number_of_children' => $ request -> get ( 'number_of_children' ) , 'interest' => $ request -> get ( 'interest' ) ?? [ ] , ] ) ; }
Display a listing of the resource.
Display a listing of the resource .
//