/** * 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; } }
/** * 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'); }