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

rizenn7's avatar

Store files and "attach" them to an user

Hi,

I'm developing an app that is supposed to manage training applications for futur students.

I have to allow applicant to upload several files (CV, cover letter, ...). I'm currently looking for a way to store those files (Flysystem), and more importantly to "attach" those files to an user. I would like each user to only have access to their files and be able to manage them (upload, delete, view).

I'm rather a beginner on Laravel (mainly doing CRUD app that only need a db) and I encounter difficulties designing a solution to my problem.

Thanks.

PS: This is a school project so my app doesn't need to be super optimized and fully secured.

0 likes
8 replies
bugsysha's avatar

Can you repeat again what is your question?

rizenn7's avatar

@bugsysha

Sorry,

I want each users to be able to upload files that will be attached to their application (candidacy).

drewdan's avatar

Upload the file, store it on the filesystem and store the file name in a table along with the user id?

1 like
judev's avatar
judev
Best Answer
Level 1

Hello,

You need another table make another migration for create a new table. If you store on your website you can use this cmd : php artisan storage:link, and after that go to migration example

Schema::create(
            'file_students', function (Blueprint $table) {
                $table->id();
                $table->string('path');
                $table->bigInteger('user_id')->unique()->unsigned(); 
//this will able you to fetch the file of you user_id,
 //user_id represent the id of the table users. If you 
 // want to get the id of an user what is connected you
//need to use auth()->user()->id; on the mass 
//assignement.
                $table->timestamps();
            }
        );

The path is the directory suite to find the files in your project. example in database image/feafjzaefzefa.png, You also need to use the {{ asset('folder_who_file_is_stored'.$images_find_by_user_id) }}

hope this help.

judev's avatar

Yo welcome ! Have an good day.

judev's avatar

But if you need to upload multiple files you need to add enctype="multipart/form-data" something like this. and on your mass assignement you can use a foreach to store every files in database and in your project.

Please or to participate in this conversation.