The Mongo db driver does not support transactions. https://github.com/jenssegers/laravel-mongodb/pull/1904
Can you track down where the transaction is started and why?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am having issues trying to create some dummy users using a factory. I keep running into the issue Call to a member function prepare() on null
Its weird that I can still select data to display, I just cant manipulate data.
Specs
Tinkerwell Error
[!] Aliasing 'User' to 'App\Models\User' for this Tinker session.
PHP Error: Call to a member function prepare() on null in /Users/ryahn/Public/Sites/globalx-dashboard/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 495
User Model
<?php
namespace App\Models;
use Illuminate\Auth\Authenticatable as AuthenticatableTrait;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Laravel\Sanctum\HasApiTokens;
use OwenIt\Auditing\Auditable as Audit;
use OwenIt\Auditing\Contracts\Auditable;
class User extends Eloquent implements Auditable, Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, Audit, AuthenticatableTrait;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $guarded = [];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Database Config
'mongodb' => [
'driver' => 'mongodb',
// 'host' => env('MONGO_HOST', '127.0.0.1'),
// 'port' => env('MONGO_PORT', 27017),
// 'database' => env('MONGO_DATABASE', 'homestead'),
// 'username' => env('MONGO_USERNAME', 'homestead'),
// 'password' => env('MONGO_PASSWORD', 'secret'),
'options' => [
// here you can pass more settings to the Mongo Driver Manager
// see https://www.php.net/manual/en/mongodb-driver-manager.construct.php under "Uri Options" for a list of complete parameters that you can use
'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'), // required with Mongo 3+
],
'dsn' => env('MONGO_DB_BASE_URI', 'mongodb://') . env('MONGO_DSN'),
],
User Factory
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
class UserFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
$email = $this->faker->unique()->safeEmail();
return [
'name' => $this->faker->name(),
'snowflake' => mt_rand(17, 99999999999999999),
'email' => $email,
'email_verified_at' => now(),
'password' => Hash::make(Str::random(20)), // password
'remember_token' => Str::random(10),
'descrim' => mt_rand(4, 9999),
'username' => $this->faker->username(),
'avatar' => 'https://i.pravatar.cc/150?u=' . $email,
'banner' => 'https://placeimg.com/960/540/tech',
'mfa_enabled' => (bool) random_int(0, 1),
];
}
/**
* Indicate that the model's email address should be unverified.
*
* @return static
*/
public function unverified()
{
return $this->state(function (array $attributes) {
return [
'email_verified_at' => null,
];
});
}
}
Please or to participate in this conversation.