app/Http/Controllers/SliderController.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) {
		$this->validate($request, [
			'nama' => 'required',
			'deskripsi' => 'required',
			'foto' => 'file|image|mimes:jpeg,png,jpg|max:2048',
		]);
		$slider = Slider::find($id);
		$slider->nama = $request->nama;
		$slider->deskripsi = $request->deskripsi;
		$nama = preg_replace('/\s+/', '', $slider->nama);
		if ($request->hasFile('foto')) {
			$file = $request->file('foto');
			$filename = $nama . '-foto.' . $file->getClientOriginalExtension();
			$path = $request->file('foto')->storeAs('public/foto-slider', $filename, 'local');
			$slider->foto = '/storage' . substr($path, strpos($path, '/'));
			if ($slider->foto) {
				$old_foto = $slider->foto;
				$old_foto_path = '/storage' . DIRECTORY_SEPARATOR . 'foto-slider' . DIRECTORY_SEPARATOR . $slider->foto;
				try {
					File::delete($old_foto_path);
				} catch (FileNotFoundException $e) {
				}
			}
			$slider->save();
		}
		$slider->save();
		return redirect()->route('slider.index')->with('success', 'Slider updated successfully');
	}
public function update ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'nama' => 'required' , 'deskripsi' => 'required' , 'foto' => 'file|image|mimes:jpeg,png,jpg|max:2048' , ] ) ; $ slider = Slider :: find ( $ id ) ; $ slider -> nama = $ request -> nama ; $ slider -> deskripsi = $ request -> deskripsi ; $ nama = preg_replace ( '/\s+/' , '' , $ slider -> nama ) ; if ( $ request -> hasFile ( 'foto' ) ) { $ file = $ request -> file ( 'foto' ) ; $ filename = $ nama . '-foto.' . $ file -> getClientOriginalExtension ( ) ; $ path = $ request -> file ( 'foto' ) -> storeAs ( 'public/foto-slider' , $ filename , 'local' ) ; $ slider -> foto = '/storage' . substr ( $ path , strpos ( $ path , '/' ) ) ; if ( $ slider -> foto ) { $ old_foto = $ slider -> foto ; $ old_foto_path = '/storage' . DIRECTORY_SEPARATOR . 'foto-slider' . DIRECTORY_SEPARATOR . $ slider -> foto ; try { File :: delete ( $ old_foto_path ) ; } catch ( FileNotFoundException $ e ) { } } $ slider -> save ( ) ; } $ slider -> save ( ) ; return redirect ( ) -> route ( 'slider.index' ) -> with ( 'success' , 'Slider updated successfully' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
#file not found