mardi 7 décembre 2021

How to set the primary key itself as a foreign key in laravel?

This sounds nooby but I wanted to know if I can make the primary key work as a foreign key in Laravel, and I'am new to Laravel.

So, I have two migrations 'User' and 'Student' as Shown below: User :

 Schema::create('users', function (Blueprint $table) {
            $table->string('uniqueId', 30)->primary();
            $table->text('password');
            $table->string('userType');
            $table->timestamps();
        });

and Student :

Schema::create('students', function (Blueprint $table) {
            $table->string('uniqueId', 30)->primary();
            $table->text('name');
            $table->text('fName');
            $table->text('mName');
            $table->text('addr');
            $table->string('image');
            $table->integer('class');
            $table->integer('roll');
            $table->string('year');
            $table->timestamps();
        });

So, all I wanted was that the primary key in Student (uniqueId) also work as a foreign key that references the 'uniqueId' column from the User table.

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire