Click here to Skip to main content
15,888,270 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
after validation not going to try or catch so can't store value

What I have tried:

<?php

namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\Alertandconsents;

use Illuminate\Http\Request;

class AlertandconsentController extends Controller
{
    public function index()
    {
        return view('patients.edit');
    }
    
    public function store(Request $request)
    {
        // dd($request->all());
        $validated = $request->validate([
            'patient_id' => 'required',
            'bpresure' => 'required',
            'h_align' => 'required',
            'rf' => 'required',
            'acb_problem' => 'required',
            'tubercalosis' => 'required',
            'sb_problem' => 'required',
            'kidney_d' => 'required',
            'smoke' => 'required',
            'hv_implant' => 'required',
            'dt' => 'required',
            'previous_il' => 'required',
            'date' => 'required',
            'u_medical_c' => 'required',
            'dmt' => 'required',
            'p_or_f' => 'required',
            'alergies' => 'required',
            'diabetics' => 'required',
            'thyroid_p' => 'required',
            'bb_disorder' => 'required',
            'epilepsy' => 'required',
            'hepatitis' => 'required',
            'hiv_aids' => 'required',
            'remark' => 'required'

    
        ]);
        try {
            dd(3);
       
            $alertandconsents = new Alertandconsents;
            $alertandconsents->patient_id = $validated['patient_id'];
            $alertandconsents->bpresure= $validated['bpresure'];
            $alertandconsents->h_align= $validated['h_align'];
            $alertandconsents->rf= $validated['rf'];
            $alertandconsents->acb_problem= $validated['acb_problem'];
            $alertandconsents->tubercalosis= $validated['tubercalosis'];
            $alertandconsents->sb_problem= $validated['sb_problem'];
            $alertandconsents->kidney_d= $validated['kidney_d'];
            $alertandconsents->smoke= $validated['smoke'];
            $alertandconsents->hv_implant= $validated['hv_implant'];
            $alertandconsents->dt= $validated['dt'];
            $alertandconsents->previous_il= $validated['previous_il'];
            $alertandconsents->date= $validated['date'];
            $alertandconsents->u_medical_c= $validated['u_medical_c'];
            $alertandconsents->dmt= $validated['dmt'];
            $alertandconsents->p_or_f= $validated['p_or_f'];
            $alertandconsents->alergies= $validated['alergies'];
            $alertandconsents->diabetics= $validated['diabetics'];
            $alertandconsents->thyroid_p= $validated['thyroid_p'];
            $alertandconsents->bb_disorder= $validated['bb_disorder'];
            $alertandconsents->epilepsy = $validated['epilepsy'];
            $alertandconsents->hepatitis = $validated['hepatitis'];
            $alertandconsents->hiv_aids = $validated['hiv_aids'];
            $alertandconsents->remark =$validated['remark'] ;
            $alertandconsents->save();
            return redirect()->route('patient.edit',['patientsId' => $request->patient_id])->with('success', 'Alert and consents are successfully added!.');
        } catch (\Exception $e) {
            dd(1);
            report($e);
            return redirect()->back()->with('error', 'Failed to add alert and consents! Please try again.');
        }
    }
}
Posted
Comments
Richard Deeming 7-Mar-22 4:02am    
That would suggest that your validate method is throwing an exception, which you are not catching since the method is called outside of the try..catch block.

Debug your code.
Richard Deeming 7-Mar-22 4:03am    
And you STILL haven't fixed the error from your previous copy of this question:
In try catch, try is not working.[^]

If you're not going to pay attention when people try to help you, then don't expect people to continue trying to help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900