app/Http/Controllers/UsahaFotoController.php
/**
	 * Store a newly created resource in storage.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @return \Illuminate\Http\Response
	 */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request, $id) {
		$this->validate($request, [
			'foto' => 'required|image|mimes:jpg,png,jpeg',
		]);
		try {
			$galeri = new UsahaFoto();
			$galeri->uuid = Uuid::uuid4()->getHex();
			$galeri->usaha_id = $id;
			$nama = preg_replace('/\s+/', '', $galeri->uuid);
			if ($request->hasFile('foto')) {
				$file = $request->file('foto');
				$filename = $nama . '-foto.' . $file->getClientOriginalExtension();
				$path = $request->file('foto')->storeAs('public/foto-usaha', $filename, 'local');
				$galeri->foto = '/storage' . substr($path, strpos($path, '/'));
				$galeri->save();
			}
			$galeri->save();
		} catch (Exception $e) {
			DB::rollback();
			Flash::error('Gagal Tambah Data');
		}
		return redirect()->route('usahafoto.index', $id)->with('success', 'Image successfully added');
	}
public function store ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'foto' => 'required|image|mimes:jpg,png,jpeg' , ] ) ; try { $ galeri = new UsahaFoto ( ) ; $ galeri -> uuid = Uuid :: uuid4 ( ) -> getHex ( ) ; $ galeri -> usaha_id = $ id ; $ nama = preg_replace ( '/\s+/' , '' , $ galeri -> uuid ) ; if ( $ request -> hasFile ( 'foto' ) ) { $ file = $ request -> file ( 'foto' ) ; $ filename = $ nama . '-foto.' . $ file -> getClientOriginalExtension ( ) ; $ path = $ request -> file ( 'foto' ) -> storeAs ( 'public/foto-usaha' , $ filename , 'local' ) ; $ galeri -> foto = '/storage' . substr ( $ path , strpos ( $ path , '/' ) ) ; $ galeri -> save ( ) ; } $ galeri -> save ( ) ; } catch ( Exception $ e ) { DB :: rollback ( ) ; Flash :: error ( 'Gagal Tambah Data' ) ; } return redirect ( ) -> route ( 'usahafoto.index' , $ id ) -> with ( 'success' , 'Image successfully added' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// 'caption' => 'required', // 'id_album' => 'required', # code... // $galeris = Galeri::where('id_album', $id)->latest()->get();