我是Laravel的新手并且在开始使用真实文件时遇到了麻烦,而不是骗子。 我想要做的是: 我有存储功能 - 将图像从pc放入我的网站。 但是当我试图进行编辑时所有崩溃 - 它不会对图像起作用:因为我正在使用提交功能 我的PhotoController:
public function create()
{
$categories = Category::all();
return view('photo.create', compact('photo','categories'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required|min:3',
'image_url'=> 'required',
'category_id' => 'required',
]);
$photo = new Photo;
if ($request->hasFile('image_url')) {
$file = $request->file('image_url');
$fileName = $request->image_url->store('');
$photo->image_url = $fileName;
}
$photo->title = $request->input('title');
$photo->description = $request->input('description');
$photo->category_id = $request->input('category_id');
$photo->save();
$request->session()->flash('create', $request->title. "Sekmingai sukurta");
$path = $request->image_url->store('public');
return redirect()->route('photos.index');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
return view('photos.index', compact('photo'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$photo = Photo::find($id );
$categories = Category::all();
return view('photo.edit', compact('photo', 'categories'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function submit(Request $request, $id)
{
$photo = Photo::find($id);
$photo->title = $request->input('title');
$photo = new Photo;
if ($request->hasFile('image_url')) {
$file = $request->file('image_url');
$fileName = $request->image_url->store('');
$photo->image_url = $fileName;
}
$photo->description = $request->input('description');
$photo->category_id = $request->input('category_id');
$photo->update();
$request->session()->flash('update', $request->title. "Sekmingai papildyta");
$path = $request->image_url->store('public');
return redirect()->route('photo.edit', $photo->id);
}
当我尝试编辑文件并上传新照片时 - 我收到错误:
"在字符串"
上调用成员函数store()
它显示错误在这一行:
$path = $request->image_url->store('public');
有人可以建议吗?谢谢