Page 92 - Laravel5_v1
P. 92

/**
                      * Update the specified resource in storage.
                      *
                      * @param  \Illuminate\Http\Request  $request
                      * @param  int  $id
                      * @return \Illuminate\Http\Response
                      */
                     public function update(StoreBooksRequest $request, $id) {
                         $book = Books::find($id);
                         /* $book->title = $request->title;
                           $book->price = $request->price;
                           $book->typebooks_id = $request->typebooks_id;
                           $book->save(); */
                         $book->update($request->all()); //mass asignment , define $fillable
                 (model)

                         return redirect()->action('BooksController@index');
                     }

                     /**
                      * Remove the specified resource from storage.
                      *
                      * @param  int  $id
                      * @return \Illuminate\Http\Response
                      */
                     public function destroy($id) {
                         $book = Books::find($id);
                         if ($book->image != 'nopic.jpg') {
                             File::delete(public_path() . '\\images\\' . $book->image);
                             File::delete(public_path() . '\\images\\resize\\' . $book->image);
                         }
                         $book->delete();
                         return redirect()->action('BooksController@index');
                     }

                 }
   87   88   89   90   91   92   93   94