存储图像功能
ProductController.php
public function store_image(Request $request, $id) {
$image = Product::find($id);
$imageupdate = $request->all();
for ($i = 1; $i < 6; $i++) {
$n = 'photo_' . $i;
if ($file = $request->file($n)) {
$name = time() . $file->getClientOriginalName();
$file->move('img/products', $name);
/*two parameter of move function are 1. name of directory and
2.name of the file to store*/
$imageupdate['photo_' . $i] = $name;
}
}
}
SQL中的产品表: