app/Http/Controllers/CcrController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Ccr  $ccr
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Ccr $ccr)
    {
        $data = request()->validate([
            'rjo_id' => 'required|exists:rjo,id',
            'file' => 'sometimes|file|max:1024',
        ]);
        if (request()->file('file')) {
            $exists = Storage::exists('public/berkas/ccr/'.$ccr->file);
            if ($exists) {
                Storage::delete('public/berkas/ccr/'.$ccr->file);
            }
            $file = $data['file'];
            $name_file = uniqid().'_rjo_no.'.$data['rjo_id'].'.'.$file->getClientOriginalExtension();
            $file = $file->storeAs('public/berkas/ccr/', $name_file);
            $data['file'] = $name_file;
        }else{
            $data['file'] = $ccr->file;
        }
        $ccr->update($data);
        $route_download = route('ccr.surat', $ccr->id);
        return redirect()->route('ccr.index')->with([
            'success' => 'Data C.C.R berhasil diubah dan surat perintah berhasil dibuat',
            'download' => $route_download
        ]);
    }
public function update ( Request $ request , Ccr $ ccr ) { $ data = request ( ) -> validate ( [ 'rjo_id' => 'required|exists:rjo,id' , 'file' => 'sometimes|file|max:1024' , ] ) ; if ( request ( ) -> file ( 'file' ) ) { $ exists = Storage :: exists ( 'public/berkas/ccr/' . $ ccr -> file ) ; if ( $ exists ) { Storage :: delete ( 'public/berkas/ccr/' . $ ccr -> file ) ; } $ file = $ data [ 'file' ] ; $ name_file = uniqid ( ) . '_rjo_no.' . $ data [ 'rjo_id' ] . '.' . $ file -> getClientOriginalExtension ( ) ; $ file = $ file -> storeAs ( 'public/berkas/ccr/' , $ name_file ) ; $ data [ 'file' ] = $ name_file ; } else { $ data [ 'file' ] = $ ccr -> file ; } $ ccr -> update ( $ data ) ; $ route_download = route ( 'ccr.surat' , $ ccr -> id ) ; return redirect ( ) -> route ( 'ccr.index' ) -> with ( [ 'success' => 'Data C.C.R berhasil diubah dan surat perintah berhasil dibuat' , 'download' => $ route_download ] ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//berkas lama //berkas baru