How to File Upload Step by Step in Laravel 10 Tutorial?

Feb 21, 2023



How to File Upload Step by Step in Laravel 10 Tutorial?

Hi friends,

Laravel 10 file upload is demonstrated in detail in this tutorial. You may upload a file in Laravel 10 with validation by using this example. We'll display the message validation and use the Laravel 10 upload file. I want to show you how to upload files in Laravel 10 with validation into the database and storage directories. Now let's develop an example of a file upload form using Laravel 10 by following a few simple steps.

And as well as, how to validate file mime type, size, dimension, etc on laravel controller by using laravel 10 validation rules.

This file upload in the tutorial will create a file upload form in laravel 10 with validation, which is used to store files in the database and storage directory.

This tutorial will work with Laravel versions 5, 6, 7, and 8. When syntax is different across versions, the different syntax will be demonstrated.

Let's start following example:

Step 1: Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app

Step 2 : Add Controller

In this step, we will create a new FileUploadController; in this file, we will add two methods index() and store() for render view and store file logic.

Let's create FileUploadController by following command:

php artisan make:controller FileUploadController



namespace App\Http\Controllers;

use Illuminate\Http\Request;

class FileUploadController extends Controller



* Display a listing of the resource.


* @return \Illuminate\Http\Response


public function index()


return view('fileUpload');



* Display a listing of the resource.


* @return \Illuminate\Http\Response


public function store(Request $request)



'file' => 'required|mimes:pdf,xlx,csv|max:2048',


$fileName = time().'.'.$request->file->extension();

$request->file->move(public_path('uploads'), $fileName);


Write Code Here for

Store $fileName name in DATABASE from HERE


return back()

->with('success','You have successfully upload file.')

->with('file', $fileName);



Store File in Storage Folder

$request->file->storeAs('uploads', $fileName);

// storage/app/uploads/file.png

Store File in Public Folder

$request->file->move(public_path('uploads'), $fileName);

// public/uploads/file.png

Store File in S3

$request->file->storeAs('uploads', $fileName, 's3');

Step 3 : Add Routes



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\FileUploadController;



| Web Routes



| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group that

| contains the "web" middleware group. Now create something great!



Route::get('upload-file', [FileUploadController::class, 'index']);

Route::post('upload-file', [FileUploadController::class, 'store'])->name('');

Step 4: Add Blade File


<!DOCTYPE html>



<title>Laravel 10 File Upload Step by Step Example -</title>

<link href="" rel="stylesheet">



<div class="container">

<div class="panel panel-primary">

<div class="panel-heading text-center mt-5">

<h2>Laravel 10 File Upload Step by Step Example -</h2>


<div class="panel-body mt-5">

@if ($message = Session::get('success'))

<div class="alert alert-success alert-dismissible fade show mb-2" role="alert">

{{ $message }}

<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>



<form action="{{ route('') }}" method="POST" enctype="multipart/form-data">


<div class="mb-3">

<label class="form-label" for="inputFile">Select File:</label>





class="form-control @error('file') is-invalid @enderror">


<span class="text-danger">{{ $message }}</span>



<div class="mb-3">

<button type="submit" class="btn btn-success">Upload</button>








Run Laravel App:

All steps have been done, now you have to type the given command and hit enter to run the laravel app:

php artisan serve

Now, you have to open web browser, type the given URL and view the app output:



I hope it can help you...

#Laravel 10