为什么此代码不起作用?
public function store(CategoryRequest $request)
{
$path = null;
if ($request->hasFile('image')) {
$file = $request->file('image');
$nane = time();
$extension = $request->file('image')->getClientOriginalExtension();
$filename = $nane . '.' . $extension;
$path = $request->file('image')->storeAs('images/categories/', $filename);
$path = Storage::putFileAs('images/categories', $request->file('image'), $filename);
}
Category::create([
'name' => $request->name,
'latin' => $request->latin,
'parent_id' => $request->parent_id,
'image' => $path,
]);
return redirect()->route('categories.index');
}
我现在在表单标签中添加了enctype="multipart/form-data"
。
我的代码是不上传,也不保存在数据库中。
我尝试了10个小时,但未能解决问题。