Exemplo n.º 1
0
 /**
  * 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;
     }
 }
Exemplo n.º 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');
 }