我正在使用laravel 5.4,我试图替换我的请求中的imagePath字段(重命名上传的图像)。laravel |如何替换表单请求中的字段?
解释:
当表单提交请求场(request->imagePath
)包含上传的图片的临时位置,我认为TMP图像移动到一个目录,而改变其名称($name
)。所以现在作为request->imagePath
仍然具有旧的tmp图像位置我想要更改request->imagePath
值以具有新的位置,然后创建用户。
像这样
if($request->hasFile('imagePath'))
{
$file = Input::file('imagePath');
$name = $request->name. '-'.$request->mobile_no.'.'.$file->getClientOriginalExtension();
echo $name."<br>";
//tried this didn't work
//$request->imagePath = $name;
$file->move(public_path().'/images/collectors', $name);
$request->merge(array('imagePath' => $name));
echo $request->imagePath."<br>";
}
但它不能正常工作,这里是输出
mahela-7829899075.jpg
C:\xampp\tmp\php286A.tmp
请帮助
只需使用它作为一个规则阵列:'$请求[ '的ImagePath'] = $ name',没有? –
@ Jean-PhilippeMurray也尝试过,但它仍然没有改变任何东西 –