app/Http/Controllers/BeritaController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Berita  $berita
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Berita $berita){
      $file = $request->file('sampul');
      if (is_null($file)) {
        $nama_file = $berita -> sampul;
      } else {
        $tujuan_upload = 'img/news';
        $nama_file = time()."_".$file->getClientOriginalName();
        $file->move($tujuan_upload,$nama_file);
      }
      Berita::where('id', $berita->id)
          ->update(
            [
              'judul' => $request -> judul,
              'sampul' => $nama_file,
              'caption' => $request -> caption,
            ]
          );
      return redirect()->route('mine.berita')->with('successBerita', 'Berita Berhasil Diubah');
    }
public function update ( Request $ request , Berita $ berita ) { $ file = $ request -> file ( 'sampul' ) ; if ( is_null ( $ file ) ) { $ nama_file = $ berita -> sampul ; } else { $ tujuan_upload = 'img/news' ; $ nama_file = time ( ) . " _ " . $ file -> getClientOriginalName ( ) ; $ file -> move ( $ tujuan_upload , $ nama_file ) ; } Berita :: where ( 'id' , $ berita -> id ) -> update ( [ 'judul' => $ request -> judul , 'sampul' => $ nama_file , 'caption' => $ request -> caption , ] ) ; return redirect ( ) -> route ( 'mine.berita' ) -> with ( 'successBerita' , 'Berita Berhasil Diubah' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .