Laravel Eloquent: Saving two foreign keys at once

Necessary to store multiple foreign keys in single database transaction to minimize database call and queries. Associate function is very important to minimize possibilities of database transactions, and security issue of database transaction. Lets assume you have a table with multiple foreign keys for example, Schema::create(‘deliveries’, function (Blueprint $table) { $table->increments(‘id’); $table->integer(‘client_id’)->unsigned()->index(); $table->foreign(‘client_id’)->references(‘id’)->on(‘clients’)->onDelete(‘cascade’); $table->integer(‘owner_id’)->unsigned()->index(); $table->foreign(‘owner_id’)->references(‘id’)->on(‘owners’)->onDelete(‘cascade’);…
Read more