コード例 #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $id = $request->get('ordine');
     $codice = $request->get('vettura');
     $stato = $request->get('stato');
     $stato = $this->stato->find($stato);
     $this->ordine->find($id)->stati()->save($stato);
     $vettura = $this->vettura->where('ordine', '=', $id)->first();
     if ($codice == null || trim($codice) == "") {
         if ($vettura != null) {
             $vettura->trash();
         }
         return Redirect::action('OrdiniController@index');
     }
     $data = array('ordine' => $id, 'vettura' => $codice);
     if ($this->vettura->validate($data)) {
         if ($vettura != null) {
             $vettura->edit($data);
         } else {
             $this->vettura->store($data);
         }
         return Redirect::action('OrdiniController@index');
     } else {
         $errors = $this->vettura->getErrors();
         return Redirect::action('OrdiniController@edit', [$id])->withInput()->withErrors($errors);
     }
 }