Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eddy1992's avatar

How to upload file and store to database ?

Hi I am New to laravel 5 . I am trying to figure out how to upload file to a database . I am attaching the screen shots please guide me how to do it .

First I made a view and used form builder . ">

This is my upload button.

I made the migrations but not sure its correct for file upload .

Controller :

Model :

Route file :

please tell me how to upload the file and store it in the database and how to add validation also on it .
Thank you in advance .

0 likes
6 replies
bobbybouwmann's avatar
Level 88

All the files are not accessible... You can put your code between backticks

` $hello = 'Hello World';`

This will display like this: $hello = 'Hello World';

If you use 3 backticks you get a code block

Here is a good guide on uploading images: http://tutsnare.com/upload-files-in-laravel/

eddy1992's avatar

Thank You for your reply . Please tell me how will I proceed .

eddy1992's avatar

Thank you for your reply . What would be the migration table for file upload ?

Mirdrack's avatar

Here you have an example for a tasks_files table, I recommend you associate your file with your main entity

Schema::create('tasks_files', function(Blueprint $table)
        {
            $table->increments('id');
            $table->integer('task_id')->unsigned();
            $table->string('name', 10);
            $table->integer('size')->unsigned();
            $table->string('real_name', 255);
            $table->string('extension', 10);
            $table->string('mime', 15);
            $table->timestamps();
            $table->softDeletes();
        });
bobbybouwmann's avatar

Why don't you first try something before asking! You are not learning from just copying here... Just give it a try and if you are stuck you come back to the forum ;)

1 like

Please or to participate in this conversation.