php - Call to a member function getClientOrginalName() on string
Get the solution ↓↓↓I cant upload file
Error Call to a member function getClientOrginalName() on string
public function store(Request $request){
$headers =new headerslider;
$headers->text=$request->input('text');
$headers->imgName = $request->input('imgName');
if (request()->hasFile('imgName')){
$headers =$request->file('imgName');
$headers->store('images','public')->getClientOrginalName();
}
$headers->save();
return redirect('admin/index');
}
Answer
Solution:
You don't need->getClientOrginalName();
after the store functionality
Laravel store functon returns the complete path of the file so you can do this
$headers->text=$request->input('text');
$headers->imgName = $request->file('imgName')->getClientOriginalName(); // Here you can get the file name.
if (request()->hasFile('imgName')){
$headers->image_path = request()->imgName->store('images','public');
// $headers->image_path <--- this is dummy. just to give an example you can have the path of file
}
$headers->save();
Answer
Solution:
You need to use that function as below:
$fileName = $request->file('imgName')->getClientOrginalName();
Answer
Solution:
You have to change this
First you have to get image name then where to store it
$headers->imgName = $request->input('imgName');
if (request()->hasFile('imgName')){
$imageName = $request->file('imgName')->getClientOrginalName();
$headers->imgName->storeAs('public/your_directory/',$imageName);
$headers->imgName = $imageName;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.