DEV Community

Al-Amin Islam
Al-Amin Islam

Posted on • Edited on

2

Easy way to Upload file use in Laravel File Storage.

When I started learning Laravel ,first time faced problem to Uploaded file. I used to Laravel package that was very complicated for me . Then I show in Laravel File Storage thats very easy to use . Today I will discuss it. I will try how to store file in my Laravel project simple.
This is exactly how I upload files my project.

Following this step by step :

First go to .env file and changed below.

APP_URL=http://127.0.0.1:8000   

FILESYSTEM_DISK=local to FILESYSTEM_DISK=public

Enter fullscreen mode Exit fullscreen mode

Create a folder inside the storage/app folder.

Example:

 storage/app/profile

Enter fullscreen mode Exit fullscreen mode

Run this command.

php artisan storage:link
Enter fullscreen mode Exit fullscreen mode

Add the following to the controller to store file

use Illuminate\Support\Facades\Storage;
use App\Models\HomePage;

 $data = $request->all();
 if ($request->file('image')) {
      $data['image'] = Storage::putFile('profile', 
            $request->file('image'));
    }
HomePage::create($data);

Enter fullscreen mode Exit fullscreen mode

In this code profile is folder name where file are upload .

😀😀 Hurry Happy Coding 😀😀

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs