app/Http/Controllers/HalamanData.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)
    {
        $fileName="";
        if ($request->hasFile('gambar')) {
            $file_path = storage_path('app/public/' . $request->gambar_lama);
        if (File::exists($file_path)) File::delete($file_path);
            $fileName = $request->gambar->store('public/images');
            $fileName = str_replace("public/", "", $fileName);
        }else{
            $fileName = $request->gambar_lama;
        }
        ModelsHalamanData::find($id)->update([
            'alamat'=>$request->alamat,
            'tanggal' => $request->tanggal,
            'tematik_id'=>$request->kecamatan,
            'jumlah_kecelakaan'=>$request->jumlah,
            'gambar'=> $fileName,
            'long'=>$request->long,
            'lat'=>$request->lat
        ]);
        return redirect()->route('halaman data');
    }
public function update ( Request $ request , $ id ) { $ fileName = " " ; if ( $ request -> hasFile ( 'gambar' ) ) { $ file_path = storage_path ( 'app/public/' . $ request -> gambar_lama ) ; if ( File :: exists ( $ file_path ) ) File :: delete ( $ file_path ) ; $ fileName = $ request -> gambar -> store ( 'public/images' ) ; $ fileName = str_replace ( " public/ " , " " , $ fileName ) ; } else { $ fileName = $ request -> gambar_lama ; } ModelsHalamanData :: find ( $ id ) -> update ( [ 'alamat' => $ request -> alamat , 'tanggal' => $ request -> tanggal , 'tematik_id' => $ request -> kecamatan , 'jumlah_kecelakaan' => $ request -> jumlah , 'gambar' => $ fileName , 'long' => $ request -> long , 'lat' => $ request -> lat ] ) ; return redirect ( ) -> route ( 'halaman data' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .