app/Http/Controllers/APIController.php
/**
     * Deletes a prescription.
     * Authorizes before deleting whether the user has permissions to delete the prescription.
     *
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
Deletes a prescription.
Authorizes before deleting whether the user has permissions to delete the prescription.

@param $id
@return \Illuminate\Http\JsonResponse
Deletes a prescription . Authorizes before deleting whether the user has permissions to delete the prescription . @param $id @return \ Illuminate \ Http \ JsonResponse
public function deletePrescription($id) {
        $prescription = Prescription::find($id);
        if (empty($prescription) || Gate::denies('deletePrescription', $prescription)) {
            return response()->json(['status'  => 0, 'message' => 'You are not authorized to delete prescriptions'
            ], 404);
        }
        if ($prescription->issued) {
            return response()->json([
                'status'  => 0,
                'message' => "The prescription is already issued. Therefore cannot be deleted"
            ], 500);
        }
        DB::beginTransaction();
        try {
            $prescription->prescriptionDrugs()->delete();
            $prescription->prescriptionPharmacyDrugs()->delete();
            $prescription->delete();
        } catch (Exception $e) {
            Log::error($e->getMessage());
            DB::rollback();
            return response()->json(['status' => 0, 'message' => $e->getMessage()], 500);
        }
        DB::commit();
        return response()->json(['status' => 1]);
    }
public function deletePrescription ( $ id ) { $ prescription = Prescription :: find ( $ id ) ; if ( empty ( $ prescription ) || Gate :: denies ( 'deletePrescription' , $ prescription ) ) { return response ( ) -> json ( [ 'status' => 0 , 'message' => 'You are not authorized to delete prescriptions' ] , 404 ) ; } if ( $ prescription -> issued ) { return response ( ) -> json ( [ 'status' => 0 , 'message' => " The prescription is already issued. Therefore cannot be deleted " ] , 500 ) ; } DB :: beginTransaction ( ) ; try { $ prescription -> prescriptionDrugs ( ) -> delete ( ) ; $ prescription -> prescriptionPharmacyDrugs ( ) -> delete ( ) ; $ prescription -> delete ( ) ; } catch ( Exception $ e ) { Log :: error ( $ e -> getMessage ( ) ) ; DB :: rollback ( ) ; return response ( ) -> json ( [ 'status' => 0 , 'message' => $ e -> getMessage ( ) ] , 500 ) ; } DB :: commit ( ) ; return response ( ) -> json ( [ 'status' => 1 ] ) ; }
Deletes a prescription.
Deletes a prescription .
//            if($prescription->prescriptionDrugs()->count()>0) { //            }