php - Looking for Laravel php developer to resolve updating function with image uploading its not working
问题描述
It's my update function and it's not showing image when I echo $fileName. It's not working like it was I want to make it with the condition if there is any image then update that image otherwise leave that I tried many times but it's not working.
public function update(Request $request, Header $header)
{
if($request->hasFile('headerimg')){
$fileName = $request->file('headerimg')->getClientOriginalName();
$request->file('headerimg')->move('uploads/header',$fileName);
}
$header->title = $request->title;
$header->discription = $request->discription;
$header->keywords = $request->keywords;
$header->headerimg = $fileName;
$header->h2 = $request->h2;
$header->breadcumb = $request->breadcumb;
$header->category = $request->category;
$header->save();
return redirect()->route('dashboard.headers.index')->with('success', 'Packages Edited Successfully');
}
解决方案
我想你的问题在你看来。也许您忘记使用enctype="multipart/form-data"
或您的输入名称与映射的控制器变量不匹配。
要找到确切的问题,请使用dd($request)
并dd($request->file('headerimg'))
查看您能否获得正确的请求。
推荐阅读
- common-lisp - dotimes 中 floor 的多个返回值
- javascript - Gatsby.js 默认起始站点未在 Typography.js 更改时更新
- rust - Rust 标准库的共享库和静态库在哪里?
- javascript - jQuery:如何添加具有在单击按钮时递增的动态 id 的 div?
- mongodb - 如果它是MongoDB中的字符串,如何有条件地将字段转换为日期?
- ruby-on-rails - 如何在 Ruby on Rails 中管理嵌套字段的多对多关系
- julia - Julia:基函数的意外扩展
- java - 依赖项失败的 Spring 控制器测试
- osgi - 刷新包捆绑
- windows - Robocopy 备份-/restartmodus (/Z) 不起作用