app/Api/V1/Controllers/InstitutionController.php
/**
     * Display a listing of the institutions.
     *
     * @param Request $request
     * @return Institution|Institution[]|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
Display a listing of the institutions.
Display a listing of the institutions .
public function index(Request $request)
    {
        $institutions = Institution::
        with('address')
            ->with('parastatals');
        if ($request->input('search') != null) {
            $search = $request->input('search');
            $institutions = Institution::query()->where(function ($query) use ($search) {
                $query->where('name', 'like', '%' . $search . '%')
                    ->orWhere('code', 'like', '%' . $search . '%')
                    ->orWhere('email', 'like', '%' . $search . '%')
                    ->orWhere('phone', 'like', '%' . $search . '%')
                    ->orWhereHas('parastatals', function ($new_query) use ($search) {
                        $new_query->where('name', 'like', '%' . $search . '%')
                            ->orWhere('code', 'like', '%' . $search . '%')
                            ->orWhere('email', 'like', '%' . $search . '%')
                            ->orWhere('phone', 'like', '%' . $search . '%');
                    });
            });
        }
        $institutions = $institutions->get();
        if ((new Institution())->showCode()) {
            $institutions->makeVisible(['code', 'phone', 'email', 'address_id', 'created_by', 'updated_by']);
            $institutions->each(function ($inst) {
                $inst->parastatals->makeVisible(['code', 'phone', 'email', 'address_id', 'created_by', 'updated_by']);
            });
        }
        return $institutions;
    }
public function index ( Request $ request ) { $ institutions = Institution :: with ( 'address' ) -> with ( 'parastatals' ) ; if ( $ request -> input ( 'search' ) != null ) { $ search = $ request -> input ( 'search' ) ; $ institutions = Institution :: query ( ) -> where ( function ( $ query ) use ( $ search ) { $ query -> where ( 'name' , 'like' , '%' . $ search . '%' ) -> orWhere ( 'code' , 'like' , '%' . $ search . '%' ) -> orWhere ( 'email' , 'like' , '%' . $ search . '%' ) -> orWhere ( 'phone' , 'like' , '%' . $ search . '%' ) -> orWhereHas ( 'parastatals' , function ( $ new_query ) use ( $ search ) { $ new_query -> where ( 'name' , 'like' , '%' . $ search . '%' ) -> orWhere ( 'code' , 'like' , '%' . $ search . '%' ) -> orWhere ( 'email' , 'like' , '%' . $ search . '%' ) -> orWhere ( 'phone' , 'like' , '%' . $ search . '%' ) ; } ) ; } ) ; } $ institutions = $ institutions -> get ( ) ; if ( ( new Institution ( ) ) -> showCode ( ) ) { $ institutions -> makeVisible ( [ 'code' , 'phone' , 'email' , 'address_id' , 'created_by' , 'updated_by' ] ) ; $ institutions -> each ( function ( $ inst ) { $ inst -> parastatals -> makeVisible ( [ 'code' , 'phone' , 'email' , 'address_id' , 'created_by' , 'updated_by' ] ) ; } ) ; } return $ institutions ; }
Display a listing of the institutions.
Display a listing of the institutions .
//        with('creator')-> //        with('updater')->