Panjangkan model pengguna untuk memanfaatkan MongoDB
P粉293341969
P粉293341969 2024-03-22 09:21:35
0
1
279

Saya cuba menggunakan Laravel dan MongoDB bersama-sama. Saya menyuruh mereka bercakap tanpa pengesahan tetapi sekarang saya mahu menambah pengguna jadi saya menggunakan beberapa sumber dan penyelesaian masalah untuk menyusunnya:

<?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'];
}

Tetapi saya mendapat ralat ini:

> {
>     "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"
>         }
>     ] }

Ada idea? Yang peliknya ialah pengguna dibuat apabila saya menghantar siaran.

P粉293341969
P粉293341969

membalas semua(1)
P粉976737101

Saya menggunakan jenseggers dan 9.2.1

Saya menghadapi masalah yang sama, penyelesaian saya ialah mengubah suai model pengguna Guna jensegers no primer

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Jenssegers\Mongodb\Auth\User as Authenticatable;
//use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;```

That said I just use breeze for the user authentication (DRY)
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!