Are you storing the file path in DB? if yes, run php artisan storage:link. then in your img tag you can access the image path using asset() function
How to display a picture that I saved into the storage folder ?
Hello everyone,
I'm saving a picture in a form, I put it into the path storage\app\documents\recettes\idRecette\pictureName\idRecette-pictureName.jpg. Here is my function :
protected const DOSSIER_DOCUMENTS_RECETTES = 'documents/recettes';
protected function getFichiersRecette($idRecette)
{
$recette = Recette::where('id_recette',$idRecette)->firstOrFail();
$dossier = self::DOSSIER_DOCUMENTS_RECETTES . '/' . $idRecette . '/' . $recette->titre;
$cheminsFichiers = Storage::files($dossier);
$fichiers = basename($cheminsFichiers);
return $fichiers;
}
What I'm trying now, is that into my function that display the homepage of the recette, I'm need to show this image into the correct path with the extension :
$recette_ALL = Recette::orderBy('created_at', 'desc')->get();
public function accueil_recette(Request $request)
{
foreach($recette_ALL as $recette){
//I need to take the path of the image
//I need to put it into an associative array ?
$data[] = array("id_recette" => $recette->id_recette, "path" => $files);
}
The problem is that I don't know how to take back the path of the current $recette. Then when I recover the path, I'll add it to the associative array with the current id_recette.
Is that right ? If yes, can someone explain me how to take back the path of the picture please ?
Cordially
EDIT :
So, I can take back the path of the image, but I have a problem, how can I save every data into associative array ? Right now, I only have the last element of my recette.
foreach($recette_ALL as $recette){
$path = 'documents/recettes/';
$files = Storage::files($path.$recette->id_recette . '/' . $recette->titre);
//I only have the last element of the for loop
$data[] = array("id_recette" => $recette->id_recette, "path" => $files);
}
Please or to participate in this conversation.