'How to assign form ID and user ID to another table

i have this table to create a new user:

{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('student_id');
        $table->string('student_faculity');
        $table->string('email')->unique();
        $table->string('usertype')->nullable();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->foreignId('current_team_id')->nullable();
        $table->string('profile_photo_path', 2048)->nullable();
        $table->timestamps();
    });
}

and this table to create a new form:

{
    Schema::create('files', function (Blueprint $table) {
        $table->id();
        $table->string('name')->nullable();
        $table->string('file_path')->nullable();
        $table->string('name_as_id')->nullable();
        $table->string('email')->nullable();
        $table->string('position')->nullable();
        $table->text('bio')->nullable();
        $table->string('approve')->nullable();
        $table->string('votes')->default('0');
        $table->string('image')->nullable();
        $table->timestamps();
    });
}

i'm trying to create a third table to handle the votes for each user (each user can vote once for each form)

how to handle the foreign key here?

i tried to create the third table like this:

{
    Schema::create('voted', function (Blueprint $table) {
        $table->id();
        $table->unsignedBigInteger('user_id');
        $table->unsignedBigInteger('file_id');

        $table->string('voted?')->default('No');

        $table->timestamps();

        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->foreign('file_id')->references('id')->on('files')->onDelete('cascade');
    });
}

but i didn't get any data when the user created or uploaded a form



Solution 1:[1]

You can find similar tables structure here: StackOverflow

Under migrations, in model class you can find relationships.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CubeStorm