J'essaie d'utiliser Laravel et MongoDB ensemble. Je les ai fait parler sans authentification mais maintenant je veux ajouter l'utilisateur, j'ai donc utilisé quelques sources et dépannage pour le mettre en place :
<?php namespace App\Models; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; //use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; use Illuminate\Database\Eloquent\Model; use Jenssegers\Mongodb\Eloquent\Model as Eloquent; use Jenssegers\Mongodb\Auth\User as Authenticatable; class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable; /** * The attributes that are mass assignable. * * @var array<int, string> */ protected $fillable = [ 'name', 'email', 'password', ]; /** * 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', ]; protected $dates = ['email_verified_at']; }
Mais j'obtiens cette erreur :
> { > "message": "Call to a member function prepare() on null", > "exception": "Error", > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Database/Connection.php", > "line": 539, > "trace": [ > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Database/Connection.php", > "line": 753, > "function": "Illuminate\Database\{closure}", > "class": "Illuminate\Database\Connection", > "type": "->" > }, > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Database/Connection.php", > "line": 720, > "function": "runQueryCallback", > "class": "Illuminate\Database\Connection", > "type": "->" > }, > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Database/Connection.php", > "line": 534, > "function": "run", > "class": "Illuminate\Database\Connection", > "type": "->" > }, > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Database/Connection.php", > "line": 498, > "function": "statement", > "class": "Illuminate\Database\Connection", > "type": "->" > }, > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php", > "line": 32, > "function": "insert", > "class": "Illuminate\Database\Connection", > "type": "->" > }, > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", > "line": 3339, > "function": "processInsertGetId", > "class": "Illuminate\Database\Query\Processors\Processor", > "type": "->" > }, > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php", > "line": 1869, > "function": "insertGetId", > "class": "Illuminate\Database\Query\Builder", > "type": "->" > }, > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php", > "line": 1330, > "function": "__call", > "class": "Illuminate\Database\Eloquent\Builder", > "type": "->" > }, > { > > ..............Trimmed as I assume you dont need it all > > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", > "line": 175, > "function": "then", > "class": "Illuminate\Pipeline\Pipeline", > "type": "->" > }, > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", > "line": 144, > "function": "sendRequestThroughRouter", > "class": "Illuminate\Foundation\Http\Kernel", > "type": "->" > }, > { > "file": "/mnt/api/public/index.php", > "line": 51, > "function": "handle", > "class": "Illuminate\Foundation\Http\Kernel", > "type": "->" > }, > { > "file": "/mnt/api/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php", > "line": 16, > "function": "require_once" > } > ] }
Des idées ? Ce qui est étrange, c'est que l'utilisateur est créé lorsque je soumets le message.
J'utilise Jenseggers et 9.2.1
J'ai été confronté au même problème, ma solution a été de modifier le modèle utilisateur Utilisez des Jensegers sans apprêt