Closed hieulvt128 closed 1 year ago
$form->image($column[, $label])->move($dir, $name);
$form->image($column[, $label])->move($dir, $name);
Thanks for your reply @styq123 But I think your answer does not resolve my problem. How this $dir include the product ID that is created only after the form submission? I try some ways and finally I found out it should like this:
$form->image('feature_image', __('Feature image'))->uniqueName()->move(function($form) {
return 'images/products/'. $form->model()->id;
});
Thanks
$form->image($column[, $label])->move($dir, $name);
Thanks for your reply @styq123 But I think your answer does not resolve my problem. How this $dir include the product ID that is created only after the form submission? I try some ways and finally I found out it should like this:
$form->image('feature_image', __('Feature image'))->uniqueName()->move(function($form) { return 'images/products/'. $form->model()->id; });
Thanks
$form->image($column[, $label])->move($dir, $name);
$dir的意思就是你需要上传文件的路径, $name就是你需要定义的文件名字。 这个cms不好用,使用文档太少,且不够灵活。网上有好多中国人写的更加好用的cms后台框架,方便且快捷,只不过用的框架基础是thinkphp或者webman,如果你感兴趣的话,可以搜搜看。
Description:
Here is my configuration in filesystems.php:
And when I submit a form to create a new Product model with:
The image would be stored to storage/app/public/images/{fileName}.jpg and the path is stored from DB being images/{fileName}.jpg. But now I want to store the image to the path that including the new Id of the Product model which has just been created. E.g: The new product is created with id=98 so I stored the image file to folder storage/app/public/images/products/98/{fileName}.jpg and images/products/98/{fileName}.jpg in DB. How I can do this?
Thanks.