Php 编辑不';我无法上传文件
我是拉雷维尔的新手,在开始处理真实文件而不是伪造文件时遇到了麻烦。 我想做的是: 我有存储功能-将图像从pc放入我的网站。 但当我试图进行编辑时,所有的程序都崩溃了——它对图像不起作用:因为我使用的是提交功能 我的光电控制器:Php 编辑不';我无法上传文件,php,laravel,laravel-5,Php,Laravel,Laravel 5,我是拉雷维尔的新手,在开始处理真实文件而不是伪造文件时遇到了麻烦。 我想做的是: 我有存储功能-将图像从pc放入我的网站。 但当我试图进行编辑时,所有的程序都崩溃了——它对图像不起作用:因为我使用的是提交功能 我的光电控制器: public function create() { $categories = Category::all(); return view('photo.create', compact('photo','categories')); } /** * Store
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');
有人能建议吗?谢谢你这样试试:
$path=$request->file('image_url')->store('public')代码>!!我已经尝试过了:然后我得到了错误:“在null上调用成员函数store()”是,如果您没有发送文件,那么您应该将其添加到if语句if($request->hasFile('image\u url'))
,以确保有文件;)谢谢你的帮助,但我有if:if($request->hasFile('image\u url')){$file=$request->file('image\u url');$fileName=$request->image\u url->store(“”);$photo->image\u url=$fileName;}像这样试试:$path=$request->file('image\u url')->store('public')代码>!!我已经尝试过了:然后我得到了错误:“在null上调用成员函数store()”是,如果您没有发送文件,那么您应该将其添加到if语句if($request->hasFile('image\u url'))
,以确保有文件;)谢谢你的帮助,但我有if:if($request->hasFile('image_url')){$file=$request->file('image_url');$fileName=$request->image_url->store(“”);$photo->image_url=$fileName;}