我有一个表格,我得到了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表字段变为空.
在if($request->hasFile('project_image'))
没有得到该领域,
另外我有形式,其中该方法是POST
与具有enctype="multipart/form-data"
和一个用于文件我有.
我做错了什么?
如果你的代码中的所有内容都会更正,那么你可能会错过enctype,我在启动时也错过了