skip to Main Content

How do I automatically insert the auth user id when creating a new model with a foreign key in Laravel?

I have a 'projects' table in my Laravel project. The migration looks something like this: Schema::create('projects', function (Blueprint $table) { $table->id(); $table->string('title'); $table->string('key')->nullable(); $table->integer('bpm')->nullable(); $table->boolean('is_collaborative')->default(false); $table->foreignId('owner_id')->constrained('users')->cascadeOnDelete(); $table->timestamps(); }); I want the owner_id field to reference a user's id in order…

VIEW QUESTION
Back To Top
Search