/**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     switch ($this->method()) {
         case 'POST':
             return ['reason' => 'required|unique:reasons'];
         case 'PATCH':
             $reason = Reason::find($this->segment(2));
             //this gets the second segment in the url which is the id of the reason
             if ($this->get('reason') == $reason['reason']) {
                 return ['reason' => 'required|unique:reasons,id' . $this->get('id')];
             } else {
                 return ['reason' => 'required|unique:reasons'];
             }
         default:
             break;
     }
 }
Example #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $reason = Reason::find($id);
     $reason->Delete('set null');
     return redirect()->action('ReasonsController@index');
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit(Request $request, $id, $cLog_id)
 {
     $cLog = CollectionLog::find($cLog_id);
     $actionOptions = [];
     $actionOptions['Text'] = 'Text';
     $actionOptions['Call'] = 'Call';
     $actionOptions['Fax'] = 'Fax';
     $actionOptions['Send SOA'] = 'Send SOA';
     $actionOptions['Email'] = 'Email';
     $actionOptions['Visit'] = 'Visit';
     $reasonOptions = Reason::lists('reason', 'id');
     $statusOptions = [];
     $statusOptions['To Do'] = 'To Do';
     $statusOptions['Done'] = 'Done';
     // $salesinvoices = SalesInvoice::where('client_id', $id)
     //             ->where('status', '!=', 'Collected')
     //             ->where('status', '!=', 'Draft')
     //             ->orderBy('status', 'asc')
     //             ->get();
     $salesinvoices = DB::SELECT("SELECT si.si_no, si.status, si.total_amount, si.date FROM sales_invoice_collection_logs sicl\n                                    JOIN sales_invoices si ON sicl.sales_invoice_id = si.id\n                                    JOIN collection_logs cl ON sicl.collection_log_id = cl.id\n                                    WHERE cl.id = '{$cLog_id}'");
     $date = Carbon::parse($cLog->date)->toFormattedDateString();
     $method = 'patch';
     return view('collection_logs.edit', compact('method', 'cLog', 'date', 'actionOptions', 'statusOptions', 'reasonOptions', 'id', 'salesinvoices'));
 }