Call to undefined function getClientOriginalName() in Laravel 8

1k Views Asked by At

I want to use the function getClientOriginalName() for making a new name for the photo I take from the user. But as I said before, it displays an error that says that this function is undefined.

$pic = $request->photo;
$newPic = time().$pic.getClientOriginalName();
1

There are 1 best solutions below

0
On BEST ANSWER

The method getClientOriginal name exists on the UploadedFile instance. To get the instance you should get by the file() method from $request object

$pic = $request->file('photo');
$newPic = time().$pic->getClientOriginalName();