app/Http/Controllers/SearchController.php
/**
     * Return Autocomplete from existing university names.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Return Autocomplete from existing university names.
@param  int  $id
@return \Illuminate\Http\Response
Return Autocomplete from existing university names . @param int $id @return \ Illuminate \ Http \ Response
public function uni(Request $request)
    {   
        $data = request(['uni_name']);
        $validator = Validator::make($data, [
            'uni_name' => ['required', 'string', 'max:255'],
        ]);
        if ($validator->fails()) {
            return response()->json(['success' => false, 'error' => $validator->messages()]);
        }
        $name = $request["uni_name"];
        $path = storage_path() . "/app/world_universities_and_domains.json";
        $json = json_decode(file_get_contents($path), true);
        $matched_uni = null;
        for($i = 0; $i < count($json); $i++){
            if( strpos(strtolower($json[$i]["name"]), strtolower($name)) !== false ){
                $matched_uni = $json[$i];
                break;
            }
        }
        return response()->json($matched_uni, 200);
    }
public function uni ( Request $ request ) { $ data = request ( [ 'uni_name' ] ) ; $ validator = Validator :: make ( $ data , [ 'uni_name' => [ 'required' , 'string' , 'max:255' ] , ] ) ; if ( $ validator -> fails ( ) ) { return response ( ) -> json ( [ 'success' => false , 'error' => $ validator -> messages ( ) ] ) ; } $ name = $ request [ " uni_name " ] ; $ path = storage_path ( ) . " /app/world_universities_and_domains.json " ; $ json = json_decode ( file_get_contents ( $ path ) , true ) ; $ matched_uni = null ; for ( $ i = 0 ; $ i < count ( $ json ) ; $ i ++ ) { if ( strpos ( strtolower ( $ json [ $ i ] [ " name " ] ) , strtolower ( $ name ) ) !== false ) { $ matched_uni = $ json [ $ i ] ; break ; } } return response ( ) -> json ( $ matched_uni , 200 ) ; }
Return Autocomplete from existing university names.
Return Autocomplete from existing university names .
// Validate search query // searched name //  return json data of universities // init possible match // Search for match // will return first found result of searched name