laravellaravel-8undefined-function

Call to undefined function getClientOriginalName() in Laravel 8


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();

Solution

  • 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();