skip to Main Content

There is no active transaction Error in creating table using Db Facade laravel

$dbConnection = DB::connection('test_connection'); $dbConnection->beginTransaction(); try{ $dbConnection->getSchemaBuilder()->create('Alpha_1', function ($table) use ($validatedData) { $table->string('name')->nullable(); }); $dbConnection->commit(); } catch (Exception $e) { // Rollback the transaction in case of error $dbConnection->rollBack(); // Get the exact database error $errorMessage = $e->getMessage(); dd($errorMessage); } I…

VIEW QUESTION

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

Laravel When Condition on a column

I have a ModelA with columns: name, last_name, email I want ModelA with the name Test to add an extra where on email what I tried is the following $model_a_res = A::when( function($query){ return $query->where('name','Test'); }, function ($query) { $query->where('email',…

VIEW QUESTION
Back To Top
Search