Laravel Display Image from Storage Folder Example

Susan Sarandon
Release: 2024-11-04 15:18:02
Original
560 people have browsed it

Laravel Display Image from Storage Folder Example

In this post, I will show you how to display image from storage app public folder in laravel 11 application.

Laravel provides a secure way to store images and files in the storage folder, preventing users from directly accessing files via URL. So, how can we display these images from the storage folder? Below, I’ll outline two methods you can use to display images securely from storage. Let’s explore both options so you can choose the one that works best for your needs. You Can Learn Using Switch Case in Laravel Blade (With Example)

Laravel 11 Display Image from Storage Folder Example

Solution 1:

first of all, we will create a Symbolic Link if you haven’t already, to make the public storage directory accessible from the web:

php artisan storage:link
Copy after login

Now, Access the Image URL in your Blade template or controller:

You can use Laravel’s Storage facade to get the URL of the image.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class HomeController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $imageUrl = Storage::url('images/your-image.jpg');
    }
}
Copy after login

Read More

The above is the detailed content of Laravel Display Image from Storage Folder Example. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!