我正在使用带有 laravel 的 docker,并且我已经安装了 mongo 并建立了与 mongo DB 的连接,我开始为 mongodb 创建迁移我使用的包是:https ://github.com/mostafamaklad/laravel-activitylog -mongodb
以前我使用的是:https ://spatie.be/docs/laravel-activitylog/v4/introduction
但是当我登录时出现此错误:
local.ERROR: http://localhost:8080/spa/login TypeError: Argument 1 passed to App\Models\User::Spatie\Activitylog\Traits\{closure}() must be an instance of Jenssegers\Mongodb\Eloquent\Model, instance of App\Models\User given, called in /var/www/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php on line 392 and defined in /var/www/vendor/mostafamaklad/laravel-activitylog-mongodb/src/Traits/DetectsChanges.php:16
在我的文件中:
config/activitylog.php
<?php
return [
'enabled' => env('ACTIVITY_LOGGER_ENABLED', true),
'delete_records_older_than_days' => 365,
'default_log_name' => 'default',
'default_auth_driver' => null,
'subject_returns_soft_deleted_models' => false,
'activity_model' => \Spatie\Activitylog\Models\Activity::class,
'table_name' => 'activity_log',
'database_connection' => env('DB_MG_CONNECTION'),
];
我的.env
DB_MG_CONNECTION=mongodb
DB_MG_HOST=umongodb
DB_MG_PORT=27017
DB_MG_DATABASE=my_bd
DB_MG_USERNAME=root
DB_MG_PASSWORD=secret
我的连接config/database.php
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_MG_HOST', 'localhost'),
'port' => env('DB_MG_PORT',27017),
'database' => env('DB_MG_DATABASE'),
'username' => env('DB_MG_USERNAME'),
'password' => env('DB_MG_PASSWORD'),
]
在我的用户模型中
<?php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Jenssegers\Mongodb\Eloquent\Model;
use Spatie\Activitylog\Models\Activity;
use Spatie\Activitylog\Traits\LogsActivity;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Contracts\Auth\CanResetPassword;
Jenssegers\Mongodb\Eloquent\Model
use App\Traits\UserDefender;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable implements JWTSubject, CanResetPassword
{
use UserDefender, Notifiable, LogsActivity;
protected $table = 'users';
protected $dates = ['deleted_at'];
}
登录时出现错误,登录,获取用户信息等不便,是通过mysql