app/Http/Controllers/Admin/BeritaController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $request->validate([
            'txtjudul_berita' => 'required',
            'txtfoto_berita' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
            'optionid_kategori_berita' => 'required',
            'txtisi_berita' => 'required',
        ]);
        $data = berita::find($id);
        $file = $request->file('txtfoto_berita');
        if ($file == "") {
            $nama_file = $data->foto_berita;
        } else {
            $gambar = berita::where('id', $id)->first();
            File::delete('front/assets/img/berita/' . $gambar->foto_beirta);
            $nama_file = time() . "_" . $file->getClientOriginalName();
        }
        $data->judul_berita = $request->get('txtjudul_berita');
        $data->foto_berita = $nama_file;
        $data->id_kategori_berita = $request->get('optionid_kategori_berita');
        $data->isi_berita = $request->get('txtisi_berita');
        $tujuan_upload = 'front/assets/img/berita';
        if ($file == "") {
        } else {
            $file->move($tujuan_upload, $nama_file);
        }
        $data->save();
        return redirect('administrator/berita')->with('sukses', 'Berita berhasil diupdate');
    }
public function update ( Request $ request , $ id ) { $ request -> validate ( [ 'txtjudul_berita' => 'required' , 'txtfoto_berita' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048' , 'optionid_kategori_berita' => 'required' , 'txtisi_berita' => 'required' , ] ) ; $ data = berita :: find ( $ id ) ; $ file = $ request -> file ( 'txtfoto_berita' ) ; if ( $ file == " " ) { $ nama_file = $ data -> foto_berita ; } else { $ gambar = berita :: where ( 'id' , $ id ) -> first ( ) ; File :: delete ( 'front/assets/img/berita/' . $ gambar -> foto_beirta ) ; $ nama_file = time ( ) . " _ " . $ file -> getClientOriginalName ( ) ; } $ data -> judul_berita = $ request -> get ( 'txtjudul_berita' ) ; $ data -> foto_berita = $ nama_file ; $ data -> id_kategori_berita = $ request -> get ( 'optionid_kategori_berita' ) ; $ data -> isi_berita = $ request -> get ( 'txtisi_berita' ) ; $ tujuan_upload = 'front/assets/img/berita' ; if ( $ file == " " ) { } else { $ file -> move ( $ tujuan_upload , $ nama_file ) ; } $ data -> save ( ) ; return redirect ( 'administrator/berita' ) -> with ( 'sukses' , 'Berita berhasil diupdate' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// nama file // upload file