I have a question with uploads of files in Laravel. I created the symbolic link with php artisan storage:link
and to upload files I am using the code below according to the Laravel doc link
public function updatePhoto(Request $request)
{
$messages = [
'photo.image' => 'Extensões aceitas: jpg, png, ou gif',
'photo.max' => 'Tamanho máximo do arquivo: 2MB',
'photo.uploaded' => 'Tamanho máximo do arquivo: 2MB',
];
$validatePhoto = $request->validate([
'photo' => 'image|max:2000',
], $messages);
$user = Auth::user();
$customer = $user->userable;
if (file_exists($customer->photo)) {
unlink($customer->photo);
}
$path = $request->file('photo')->store('public');
$path = str_replace('public', 'storage', $path);
$customer->photo = $path;
$customer->save();
Session::flash('alert-success', 'Foto alterada com sucesso!');
return redirect()->back();
}
This stores the image in storage / app / public and saves the path to the database: public / imagem.jpeg which is what I need.
To display the image I'm using:
{{ asset(Auth::user()->userable->photo) }}
The problem is that without using str_replace () to rename public / imagem.jpg to storage / imagem.jpg the image does not appear. How do I display the image using this Laravel store ('public') method without needing to use str_replace ()?