HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/ghayatcom/ghayatcom-api/app/Http/Controllers/Api/GeneralHealthConditionController.php
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\GeneralHealthCondition;
use Illuminate\Http\Request;

class GeneralHealthConditionController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        try {

            $paginate = $request->count_per_page ? $request->count_per_page : 10;
            $pageNumber = $request->page ? $request->page : 1;
            $search_key = $request->search ? $request->search : '';
            $list_type = $request->list_type ? $request->list_type : 'list'; //paginate
            /**
             * @var int|null $paginate
             * @var int|null $pageNumber
             * @var string|null $search_key
             * @var string|null $list_type
             */

            $sort_by_col = (isset($request->sort_by)) ? $request->sort_by : 'id';
            $data_order_by = $request->order_by;
            /** @var string $data_order_by */
            $orderBy = $data_order_by ? strtoupper($data_order_by) : strtoupper('asc');

            $list = GeneralHealthCondition::whereNotNull('id');
            
            if(!empty($search_key)) {
                $list = $list->where(function($q) use($search_key){
                    $q->where('name', 'LIKE', "%{$search_key}%");
                });
            }

            if($sort_by_col) {
                /**
                 * @var string $sort_by_col
                 * @var string $orderBy
                 */
                $list = $list->orderBy($sort_by_col, $orderBy);
            }

            if($list_type == 'paginate') {
                return self::sentResponse(200, $list->paginate($paginate), __('digimed_validation.success_response.data_fetch_success'));
            } else {
                return self::sentResponse(200, $list->get(), __('digimed_validation.success_response.data_fetch_success'));
            }
        } catch(Exception | Throwable | QueryException $e) {
            return self::sentResponse(500, [], $e->getMessage());
        }
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\GeneralHealthCondition  $generalHealthCondition
     * @return \Illuminate\Http\Response
     */
    public function show(GeneralHealthCondition $generalHealthCondition)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\GeneralHealthCondition  $generalHealthCondition
     * @return \Illuminate\Http\Response
     */
    public function edit(GeneralHealthCondition $generalHealthCondition)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\GeneralHealthCondition  $generalHealthCondition
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, GeneralHealthCondition $generalHealthCondition)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\GeneralHealthCondition  $generalHealthCondition
     * @return \Illuminate\Http\Response
     */
    public function destroy(GeneralHealthCondition $generalHealthCondition)
    {
        //
    }
}