app/Http/Controllers/BukuController.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)
    {
        if($request->file('cover')) {
            $file = $request->file('cover');
            $dt = Carbon::now();
            $acak  = $file->getClientOriginalExtension();
            $fileName = rand(11111,99999).'-'.$dt->format('Y-m-d-H-i-s').'.'.$acak;
            $request->file('cover')->move("images/buku", $fileName);
            $cover = $fileName;
        } else {
            $cover = NULL;
        }
        Buku::find($id)->update([
             'judul' => $request->get('judul'),
                'isbn' => $request->get('isbn'),
                'pengarang' => $request->get('pengarang'),
                'penerbit' => $request->get('penerbit'),
                'tahun_terbit' => $request->get('tahun_terbit'),
                'jumlah_buku' => $request->get('jumlah_buku'),
                'deskripsi' => $request->get('deskripsi'),
                'lokasi' => $request->get('lokasi'),
                'cover' => $cover
                ]);
        alert()->success('Berhasil.','Data telah diubah!');
        return redirect()->route('buku.index');
    }
public function update ( Request $ request , $ id ) { if ( $ request -> file ( 'cover' ) ) { $ file = $ request -> file ( 'cover' ) ; $ dt = Carbon :: now ( ) ; $ acak = $ file -> getClientOriginalExtension ( ) ; $ fileName = rand ( 11111 , 99999 ) . '-' . $ dt -> format ( 'Y-m-d-H-i-s' ) . '.' . $ acak ; $ request -> file ( 'cover' ) -> move ( " images/buku " , $ fileName ) ; $ cover = $ fileName ; } else { $ cover = NULL ; } Buku :: find ( $ id ) -> update ( [ 'judul' => $ request -> get ( 'judul' ) , 'isbn' => $ request -> get ( 'isbn' ) , 'pengarang' => $ request -> get ( 'pengarang' ) , 'penerbit' => $ request -> get ( 'penerbit' ) , 'tahun_terbit' => $ request -> get ( 'tahun_terbit' ) , 'jumlah_buku' => $ request -> get ( 'jumlah_buku' ) , 'deskripsi' => $ request -> get ( 'deskripsi' ) , 'lokasi' => $ request -> get ( 'lokasi' ) , 'cover' => $ cover ] ) ; alert ( ) -> success ( 'Berhasil.' , 'Data telah diubah!' ) ; return redirect ( ) -> route ( 'buku.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .