HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/dev-telemedicina.teky.com.co/app/Http/Controllers/SpecialtyController.php
<?php

namespace Telemedicina\Http\Controllers;

use Illuminate\Http\Request;
use Telemedicina\Specialty;
Use Session;
Use Redirect;

class SpecialtyController extends Controller
{
    /**
    * Display a listing of the resource.
    *
    * @return \Illuminate\Http\Response
    */
    public function index()
    {
        $obj = Specialty::orderBy('name')->paginate(15);
        return view('specialties.main')
        ->with('specialties', $obj);
    }

    /**
    * 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)
    {
        $validatedData = $request->validate([
            'name' => 'required',
            'code_cp' => 'required',
            ]);

            $obj = new Specialty;
            $obj->name = $request->name;
            $obj->code_cp = $request->code_cp;

            if($request->sex_allowed == 3 || !$request->sex_allowed){
                $obj->f = true;
                $obj->m = true;
            }else if($request->sex_allowed == 1){
                $obj->m = true;
                $obj->f = false;
            }else if($request->sex_allowed == 2){
                $obj->f = true;
                $obj->m = false;
            }

            $obj->save();


            Session::flash('data', array('type' => 'success', 'message' => __('messages.specialties.ok_create')));

            return redirect()->back();
        }

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

        /**
        * Show the form for editing the specified resource.
        *
        * @param  int  $id
        * @return \Illuminate\Http\Response
        */
        public function edit($id)
        {
            $obj = Specialty::find($id);
            return view('specialties.edit', compact('obj'));
        }

        /**
        * Update the specified resource in storage.
        *
        * @param  \Illuminate\Http\Request  $request
        * @param  int  $id
        * @return \Illuminate\Http\Response
        */
        public function update(Request $request, $id)
        {
            $validatedData = $request->validate([
                'name' => 'required',
                ]);

                $obj = Specialty::find($id);
                $obj->name = $request->name;

                if($request->sex_allowed == 3 || !$request->sex_allowed){
                    $obj->f = true;
                    $obj->m = true;
                }else if($request->sex_allowed == 1){
                    $obj->m = true;
                    $obj->f = false;
                }else if($request->sex_allowed == 2){
                    $obj->f = true;
                    $obj->m = false;
                }

                $obj->save();

                Session::flash('data', array('type' => 'success', 'message' => __('messages.specialties.ok_update')));
                return Redirect::to('specialties');
            }

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

            public function active(Request $request){

                $id= $request['id'];
                $estado=  $request['estado'];
                $zhc = Specialty::where('id', '=',$id)->first();
                $zhc->active = $estado;
                $zhc->update();

                $res[] = array('respuesta' => true);
                $dres = json_encode($res);
                return json_decode($dres, true);

            }

            public function getSexAllowed(Request $request){
                $obj = Specialty::find($request->specialty_id);
                $res = [];
                if($obj->m){
                    array_push($res, array('sexo' => 'Masculino', 'id' => 1));
                }

                if($obj->f){
                    array_push($res, array('sexo' => 'Femenino', 'id' => 2));
                }

                return $res;
            }
        }