Clement S.M.
Clement S.M.

Reputation: 21

BadMethodCallException Method Illuminate\Database\Query\Builder::input does not exist

Am getting that error when submitting my form data for storing , Below is my approve_request_post function in controller.

public function approve_request_post(Request $request, $request_hash)
{
    $request->validate([
    'hosp_no' => 'required',
    'transport_cost' => 'required',
    'days' => 'required|numeric',
    'per_diem' => 'required|numeric',
    'service_type' => 'required',
    'trans_mean' => 'required',
    'cost_payable' => 'required|numeric',
    'patient_age' => 'required|numeric',
    'doctors_name' => 'required',
    'appointment_date' => 'required|date',
    'comment' => 'required',
    ]);


    // Start transaction
    DB::beginTransaction();


    $request = ReferralRequestModel::where('request_hash', $request_hash)->firstOrFail();

    $remark = new InsurerRemarksModel;
    $remark->ir_hash = encrypt($remark->ir_id);
    $remark->req_id = $request->request_id;
    $remark->insurer_id = Auth::user()->insurers->insurer_id;
    $remark->req_id = $request->request_id;
    $remark->hosp_no = $request->input('hosp_no');
    $remark->service_type = $request->input('service_type');
    $remark->transport_cost = $request->input('transport_cost');
    $remark->trans_mean = $request->input('trans_mean');
    $remark->days = $request->input('days');
    $remark->cost_payable = $request->input('cost_payable');
    $remark->patient_age = $request->input('patient_age');
    $remark->doctors_name = $request->input('doctors_name');
    $remark->appointment_date = $request->input('appointment_date');
    $remark->approval_date =Carbon::now();
    $remark->ir_status = 'approved';
    $remark->save();

    //approvalrecord
    $approval = new ApprovalModel;
    $approval->req_id = $request->request_id;
    $approval->approver_id = Auth::user()->id;
    $approval->category = 'Insurer | Verified By: ';
    $approval->status = 'Verified';
    $approval->comment = $request->input('comment');
    $approval->save();

    //email to all medical team

    if( !$remark->save() || !$approval->save() )
    {
        DB::rollback();
        return back()->withInput(Input::all())->with('failure', 'Transaction Not Successful. Check the input data');
    }

    DB::commit();

    return redirect('/insurer-view-submitted-requests')->with('success', 'Referral Request Approved  Successfully');
}

Upvotes: 0

Views: 361

Answers (1)

bhavinjr
bhavinjr

Reputation: 1763

Replace this line

$referral_model = ReferralRequestModel::where('request_hash', $request_hash)->firstOrFail();

Because you are replacing the $request with a model instance and trying to get the value using $request->input('hosp_no') something like that

$request->input('hosp_no') that method will try to get input method from your ReferralRequestModel

so replace the above line and use $referral_model where you want.

also suggest to use try , catch block for handle exception. because firstOrFail throw Illuminate\Database\Eloquent\ModelNotFoundException exception if data is not found

Upvotes: 2

Related Questions