26th Nov 2025
Image uploading is one of the most common and essential features in web applications. Whether you’re building a blog, an admin panel, or an eCommerce store — you’ll often need to upload and manage images.
In this guide, we’ll learn how to upload images in Laravel step-by-step using different methods — including store() and getClientOriginalExtension().
This tutorial is written for beginners, explained in simple words, and completely SEO optimized.
๐งฑ Step 1: Setup Your Laravel Project
If you don’t have a Laravel project yet, create one using the command below:
composer create-project laravel/laravel image_upload_tutorial
Then go inside your project folder:
Start your development server:
๐งฐ Step 2: Create Controller
We’ll create a controller to handle the image upload logic.
php artisan make:controller ImageController
This will create a new file at:
app/Http/Controllers/ImageController.php
๐๏ธ Step 3: Create Upload Form (View File)
Let’s create a simple form to upload an image.
Go to resources/views and create a new file: upload.blade.php
โ Important:
-
enctype="multipart/form-data"is required for file uploads. -
@csrfis mandatory to protect your form from CSRF attacks.
โ๏ธ Step 4: Define Routes
Open routes/web.php and add:
๐งฉ Step 5: Image Upload Method #1 — Using store()
Now open your controller (ImageController.php) and add this code:
๐ Explanation:
-
store('uploads', 'public'): Saves file inside/storage/app/public/uploads. -
max:2048: Restricts file size to 2MB. -
Laravel automatically gives a unique name to each file.
โ Advantages:
-
Very simple and clean.
-
Laravel handles naming and path management.
-
Perfect for most use cases.
๐งฉ Step 6: Image Upload Method #2 — Using getClientOriginalExtension()
If you want full control over how the image is named and where it’s stored, use this method.
๐ Explanation:
-
getClientOriginalExtension(): Returns the original extension of the uploaded file. -
move(public_path('uploads'), $filename): Saves image manually in/public/uploads. -
You control filename, folder, and structure yourself.
โ Advantages:
-
Full customization of naming.
-
Useful when you want to store files in specific locations.
-
Common in admin panels and CMS systems.
๐๏ธ Step 7: Display Uploaded Images
If you want to display the uploaded image after saving, use:
OR if you saved manually with move():
๐ง Step 8: Common Issues & Fixes
1๏ธโฃ Storage not accessible in browser
Run this command:
It links /storage to /public/storage.
2๏ธโฃ Folder not found?
Make sure the folder exists:
If not, create it manually.
3๏ธโฃ Permission denied?
Give write permission:
โก Step 9: Bonus — Store Image Path in Database
If you’re saving image info in a database:
$imagePath = $request->file('image')->store('uploads', 'public');
ModelName::create([
'title' => $request->title,
'image' => $imagePath
]);
And display it in Blade:
<img src="{{ asset('storage/' . $model->image) }}" width="150">
๐งพ Comparison Between Both Methods
| Feature | store() |
getClientOriginalExtension() + move() |
|---|---|---|
| Naming | Automatic (unique hash) | Custom (you define) |
| Path | Inside storage/app/public/uploads |
Inside public/uploads |
| Control | Less manual control | Full control |
| Use Case | Simple uploads | Custom folder structure |
โ Conclusion
Laravel makes image uploading super easy with multiple built-in methods.
-
Use
store()if you want Laravel to handle everything automatically. -
Use
getClientOriginalExtension()+move()if you want full control over naming and location.
By following this step-by-step guide, you can easily implement image uploads in your Laravel project — whether for blogs, admin dashboards, or product galleries.
Leave A Reply
Your email address will not be published. Required fields are marked