Upload files in many inputs - laravel
Clash Royale CLAN TAG#URR8PPP
Upload files in many inputs - laravel
I have a form that I'm trying to upload two files from two different inputs but I have problems in my controller and I don't know how to write store & update function !!!?
My store Function it works but I'm not sure it's correct.
AdminController.php :
class AdminController extends Controller
protected function singerUploadImage($file)
$year = Carbon::now()->year;
$filename = date('Y_m_d') . '_' . $file->getClientOriginalName();
$destination = "/uploads/images/$year/singers";
$destinationPath = public_path($destination);
$file->move($destinationPath, $filename);
return $destination . '/' . $filename;
SingerController.php :
class SingerController extends AdminController
/**
* Store a newly created resource in storage.
*
* @param SingerRequest
1 Answer
1
SingerController :
public function update(Request $request, Singer $singer)
$imageUrl = $request->file(['singer_image' , 'singer_bg']);
$input = $request->all();
if ($request->hasFile($imageUrl['singer_image']))
$input ['singer_image'] = $this->singerUploadImage($request->file('singer_image'));
else
$input ['singer_image'] = $singer->singer_image;
if($request->hasFile($imageUrl['singer_bg']))
$input ['singer_bg'] = $this->singerUploadImage($request->file('singer_bg'));
else
$input ['singer_bg'] = $singer->singer_bg;
$singer->update($input);
return redirect(route('singers.index'));
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.