php - Call to a member function getClientOrginalName() on string ← (PHP, Laravel)
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;
}