Convert image to base 64 string with Laravel
It worked for me in the following way:
$image = base64_encode(file_get_contents($request->file('image')));
I eliminated this part ->path();
Laravel's $request->file()
doesn't return the actual file content. It returns an instance of the UploadedFile
-class.
You need to load the actual file to be able to convert it:
$image = base64_encode(file_get_contents($request->file('image')->path()));