I am using Amazon S3 to add files to it for my business registration system.
Inside the store method I have the following:
$input = $request->all();
$files = isset($input['file']) ? $input['file'] : array ();
$business_names = json_decode($input['business_names'], true);
$business_details = json_decode($input['business_details']);
$share_amount = json_decode($input['share_amount'], true);
$entity = json_decode($input['entity'], true);
$directors = json_decode($input['directors'], true);
$shareholders = json_decode($input['shareholders'], true);
$appointments = json_decode($input['appointments'], true);
$input['user_id'] = Auth::user()->id;
Log::info(Auth::user());
Log::info($request->user());
/* Create Business Record */
$business = new Business;
$business->business_names = json_encode($business_names);
$business->share_amount = $share_amount ?: 0;
$business->entity = $entity ?: '';
$business->business_physical_address = json_encode($business_details->physical_address);
$business->has_business_postal_address = $business_details->has_postal_address;
$business->business_postal_address = json_encode($business_details->postal_address);
$business->user_id = $input['user_id'];
$business->save();
/* Upload Files */
foreach($files as $file) {
if ($file) {
Storage::disk()->put($file->getClientOriginalName(), fopen($file, 'r+'), 'public');
// $file->storeAs('files/' . $business->id, $file->getClientOriginalName());
}
}
All works until now...but what I want something more organized, in a sense that, every time I save a new business, a folder is also created with that business id and the images should be added to that particular folder.
I tried this:
Storage::disk('s3')->put($file->getClientOriginalName(), fopen($file, 'r+'), 'public/' . $business->id);
But I see the following error when I try to save a business:
#0 C:\xampp\htdocs\startingabandbaby\vendor\league\flysystem\src\Adapter\Local.php(356): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', 'C:\xampp\htdocs...', 356, Array)
Any way around that?