Laravel : $request->hasFile() 不工作
2022-08-30 16:49:06
我有一个表格,我得到,和一个.当 i 时,它返回以下正确的内容。title
description
image
dd($requests->all());
array:4 [
"projectTitle" => "asd"
"project_description" => "asd"
"project_image" => "15940723_1336567063030425_9215184436331587115_n.jpg"
"_token" => "eUj27iioySvIgut5Afu0ZHMgeVrO99a9e1o7Tw0w"
]
我将值存储为:
$project = new Portfolio;
$project->freelancer_id = Auth::user()->id;
$project->title = $request->get('projectTitle');
$project->description = $request->get('project_description');
if($request->hasFile('project_image')){
$project_image = $request->file('project_image');
$filename = time() . '.' . $project_image->getClientOriginalExtension();
Image::make($project_image)->resize(197, 137)->save( public_path('/uploads/portfolios/' . $filename ) );
$project->img = $filename;
}
$project->save();
但 img
DB 表字段将变为 null。
没有得到这个领域,if($request->hasFile('project_image'))
另外,我有形式,其中的方法是什么,有和一个文件我有.POST
enctype="multipart/form-data"
<input type="file" name="project_image" id="project_image">
我做错了什么?