Before we start I need to say, that storing files in Database can be very dangerous! If your DB Server does not have the required resources to run, you will have some real problems! Also don't forget that MySql was never meant to be File Storing Database Solution! If you need to store large amount of files, or to handle some intensive traffic, you'd better use MongoDB!

So, now! Lets start!

First things first! Lets create our Database Migration:

    public function up()
    {
        Schema::create('files', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('size');
            $table->string('name', 255);
            $table->string('mime', 255);
            $table->binary('contents');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('files');
    }

As you can see the column contents is binary, which in MySql is Blob (Binary large object). We'd say that blob in MySql can handle upto 64kb, and that's not enough for our purposes! So we gotta change it after we excecute the migration to LONGBLOB which one can handle upto 4Gigs of content.
(You can change it through PHPMyAdmin or even through the MySQL console)

Secondly we need to create our Model

class UploadedFile extends Model
{
    protected $table = 'files';

    protected $fillable = ['name', 'mime', 'size', 'contents'];

}

Good! Now lets create our FormRequest

class FileUploadRequest extends FormRequest
{

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'file' => 'required|file',
        ];
    }
}

 

Now lets create our View

@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">FileUpload</div>

                    <div class="card-body">
                        @if(Session::has('success'))
                            <div class="alert alert-success" role="alert">
                                {{ Session::get('success') }}
                            </div>
                        @elseif(Session::has('error'))
                                <div class="alert alert-danger" role="alert">
                                    {{ Session::get('error') }}
                                </div>
                            @endif
                        <form action="{{route('file.upload')}}" method="post" enctype="multipart/form-data">
                            @csrf
                            @if ($errors->any())
                                @foreach ($errors->all() as $error)
                                    {{ $error }}
                                @endforeach
                            @endif
                            <div class="form-group">
                                <input class="form-control-file" type="file" name="file" required>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-success" type="submit">Upload</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

We're almost there!! Now lets create our Controller of course

class FileController extends Controller
{

    public function index()
    {
        return view('upload');
    }

    public function upload(FileUploadRequest $request)
    {
        $validated = $request->validated();
        $uploadedFile = $validated['file'];
        $file = new UploadedFile();
        $file->size = $uploadedFile->getSize();
        $file->mime = $uploadedFile->getMimeType();
        $file->contents = File::get($validated['file']->getRealPath());
        $file->name = $validated['file']->getClientOriginalName();
        if ($file->save()) {
            session()->flash('success', 'File Has Uploaded Successfully!');
            return redirect()->back();
        }
        session()->flash('error', 'A Problem Has Occurred And The File Could Not Be Uploaded!');
        return redirect()->back();
    }

    public function download(UploadedFile $uploadedFile)
    {
        return response($uploadedFile->contents)
            ->header('Content-Type', $uploadedFile->mime)
            ->header('Content-disposition', 'attachment; filename="'.$uploadedFile->name.'"');
    }
}

And lastly, you need to register the Routes!

Route::get('/', '[email protected]')->name('file.index');
Route::post('/', '[email protected]pload')->name('file.upload');
Route::get('/download/{uploadedFile}', '[email protected]')->name('file.download');

That's it! If you want to upload some large files, you must change the configurations in php.ini & my.ini files!