From that picture, it looks like the image is part of restocks table. so, one restock has exactly one image from that image (one to one).
Well, a user may have one or more restocks (one to many) but a restock has one image. therefore
- Save user record (create)
for example:
$user = User::create(['name'=>$request->get('name'), 'address'=>$rquest->get('address')]);
now you have the user saved.
- save restock (without image, therefore make image column nullable) (create)
example:
$restock = new Resocks();
$restock->address=$request->get('address');
$restock->phone=$request->get('phone');
.
.
.
$restock->restock_user_id=$user->id;//because you saved the user
$restock->save();
then you go to upload section.
This is where you do the edit, because you are going to add image location after you upload
example:
$restock = findOfFail($request->get('restock'));
if(isset($request->get('image))
{
$image=$$request->get('image');
$extension = $image->getClientOriginalExtension();
$storage = '/app/Pictures/';
$fileNameNoStorage= str_random(100).$image->getFilename() . '.' . $extension;
$fileName = $storage.$fileNameNoStorage;
$image->move(storage_path() . $storage, $fileName);
$restock->image=$fileNameNoStorage;
$restock->save();
}
That's how I would do that