0

Laravel 版本: 7.16.1
PHP 版本: 7.4
数据库驱动和版本: "jenssegers/mongodb": "4.0.0-alpha.1"

我有一个从控制台调用的队列应用程序。当我想插入集合时,我遇到了错误。原因是什么?我认为错误。

> Class 'Jenssegers\Mongodb\Eloquent\Model' not found
> {"exception":"[object] (Error(code: 0): Class
> 'Jenssegers\Mongodb\Eloquent\Model' not found

当我在浏览器上正常使用时。没关系。

我做了“composer dump-autoload”,但没有改变任何东西。

我的结构:

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
        'Illuminate\Auth\Events\Logout' => [
            'App\Listeners\LogSuccessfulLogout',
        ],
        'eloquent.created: *' => [
            'App\Listeners\EloquentListener',
        ],
        'eloquent.updated: *' => [
            'App\Listeners\EloquentListener',
        ],
        'eloquent.deleted: *' => [
            'App\Listeners\EloquentListener',
        ],
        'eloquent.restored: *' => [
            'App\Listeners\EloquentListener',
        ]
    ];



<?php

namespace App\Listeners;

use App\Http\Controllers\Common\Models\ActivityLogs;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class EloquentListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  Logout  $event
     * @return void
     */
    public function handle($event, $data)
    {
        $disableFire = [
            'ActivityLogs'
        ];

        $continue = true;
        foreach ($disableFire as $item) {
            $continue = strstr($event, $item) ? false: true;
        }

        if ($continue) {
            ActivityLogs::create([
                'fire_event' => $event,
                'user_id' => auth()->id(),
                'site_id' => auth()->user()->site_id
            ]);
        }

        return true;

    }

}

<?php

namespace App\Http\Controllers\Common\Models;

use Jenssegers\Mongodb\Eloquent\Model;
use Jenssegers\Mongodb\Eloquent\SoftDeletes;

class ActivityLogs extends Model {

    use SoftDeletes;

    protected $dates = ['created_at', 'updated_at', 'deleted_at'];

    protected $collection = 'activity_logs';

    protected $connection = 'mongodb';

    protected $fillable = [
        //'activity_log_id',
        'fire_event',
        'site_id',
        'user_id',
        'deleted_at',
        'created_at',
        'updated_at'
    ];
}
4

1 回答 1

0

你在配置中配置了 queue.php 吗?

https://github.com/jenssegers/laravel-mongodb#queues

您是否配置了 .env 文件?

你安装包了吗?

作曲家需要 jensegers/mongodb

这是带有示例的教程的链接

https://appdividend.com/2018/05/10/laravel-mongodb-crud-tutorial-with-example/

于 2020-06-17T19:34:47.337 回答