app/Http/Controllers/PatientController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {   
        $this->validateWith([
            'patient_name' => 'required',
            'gender' => 'required'
        ]);
        $config = [
            'table' => 'patients',
            'field' => 'lab_id',
            'length' => 10,
            'prefix' => 'DGA-'
        ];
        $lab_id = IdGenerator::generate($config);
        $pat = new Patient;
        $pat->lab_id = ( string ) $lab_id;
        $pat->lab_pw = Str::random(6);
        $pat->test_option = $request->test_option;
        $pat->patient_name = $request->patient_name;
        $pat->patient_age = $request->patient_age;
        $pat->year_or_month = $request->year_or_month;
        $pat->gender = $request->gender;
        $pat->phone = $request->phone;
        $pat->dob = $request->dob;
        $pat->landline = $request->landline;
        $pat->email = $request->email;
        if($request->email || $request->email_2){
            $pat->email_1 = $request->email_1;
            $pat->email_2 = $request->email_2;
        }
        $pat->province = $request->province;
        $pat->district = $request->district;
        $pat->municipality = $request->municipality;
        $pat->ward = $request->ward;
        $pat->refering_physician = $request->refering_physician;
        $pat->specimen = $request->specimen;
        $pat->specimen_coll_site = $request->specimen_coll_site;
        $pat->specimen_coll_date = $request->specimen_coll_date;
        $pat->specimen_coll_time = $request->specimen_coll_time;
        $pat->reporting_date = $request->reporting_date;
        $pat->reporting_time = $request->reporting_time;
        $pat->morbidity = $request->morbidity;
        $pat->temperature = $request->temperature;
        $pat->sputum = $request->sputum;
        $pat->symptoms = $request->symptoms;
        $pat->symptoms_if_any = $request->symptoms_if_any;
        $pat->travel_history = $request->travel_history;
        $pat->country_visited = $request->country_visited;
        $pat->close_contact = $request->close_contact;
        $pat->admit_isolation_ward = $request->admit_isolation_ward;
        $pat->passport = $request->passport;
        $pat->reference = $request->reference;
        $pat->remark = $request->remark;
        $pat->user_id = Auth::user()->id;
        $pat->save();
        Session::flash('success', 'Succesfully created Patient Information.');
        return redirect()->back();
    }
public function store ( Request $ request ) { $ this -> validateWith ( [ 'patient_name' => 'required' , 'gender' => 'required' ] ) ; $ config = [ 'table' => 'patients' , 'field' => 'lab_id' , 'length' => 10 , 'prefix' => 'DGA-' ] ; $ lab_id = IdGenerator :: generate ( $ config ) ; $ pat = new Patient ; $ pat -> lab_id = ( string ) $ lab_id ; $ pat -> lab_pw = Str :: random ( 6 ) ; $ pat -> test_option = $ request -> test_option ; $ pat -> patient_name = $ request -> patient_name ; $ pat -> patient_age = $ request -> patient_age ; $ pat -> year_or_month = $ request -> year_or_month ; $ pat -> gender = $ request -> gender ; $ pat -> phone = $ request -> phone ; $ pat -> dob = $ request -> dob ; $ pat -> landline = $ request -> landline ; $ pat -> email = $ request -> email ; if ( $ request -> email || $ request -> email_2 ) { $ pat -> email_1 = $ request -> email_1 ; $ pat -> email_2 = $ request -> email_2 ; } $ pat -> province = $ request -> province ; $ pat -> district = $ request -> district ; $ pat -> municipality = $ request -> municipality ; $ pat -> ward = $ request -> ward ; $ pat -> refering_physician = $ request -> refering_physician ; $ pat -> specimen = $ request -> specimen ; $ pat -> specimen_coll_site = $ request -> specimen_coll_site ; $ pat -> specimen_coll_date = $ request -> specimen_coll_date ; $ pat -> specimen_coll_time = $ request -> specimen_coll_time ; $ pat -> reporting_date = $ request -> reporting_date ; $ pat -> reporting_time = $ request -> reporting_time ; $ pat -> morbidity = $ request -> morbidity ; $ pat -> temperature = $ request -> temperature ; $ pat -> sputum = $ request -> sputum ; $ pat -> symptoms = $ request -> symptoms ; $ pat -> symptoms_if_any = $ request -> symptoms_if_any ; $ pat -> travel_history = $ request -> travel_history ; $ pat -> country_visited = $ request -> country_visited ; $ pat -> close_contact = $ request -> close_contact ; $ pat -> admit_isolation_ward = $ request -> admit_isolation_ward ; $ pat -> passport = $ request -> passport ; $ pat -> reference = $ request -> reference ; $ pat -> remark = $ request -> remark ; $ pat -> user_id = Auth :: user ( ) -> id ; $ pat -> save ( ) ; Session :: flash ( 'success' , 'Succesfully created Patient Information.' ) ; return redirect ( ) -> back ( ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// now use it // $lab_id = 'INX-100009'; // output: 160001 // $pat->lab_id = $lab_id;