0

Laravel Version: 7.16.1
PHP Version: 7.4
Database Driver & Version: "jenssegers/mongodb": "4.0.0-alpha.1"

I have a queue application that I call from the console. When I want to insert collection I am getting below error. What would be the reason? I think bug.

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

When I use normal on browser. Its okay.

I made "composer dump-autoload" but not changed anything.

my structure:

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'
    ];
}
felipsmartins
  • 13,269
  • 4
  • 48
  • 56
omero
  • 93
  • 1
  • 4
  • 10

1 Answers1

0

Have u configured queue.php at config?

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

Have u configured the .env file ??

did u install the package?

composer require jenssegers/mongodb

This is a link for a tutorial with an example

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

Mostafa Hana
  • 115
  • 2
  • 8
  • Unfortunately, it's not related to queue. I am using redis with queue. I use mongodb in the event listener. When I use on browser it is okay no premlem. I can CRUD on model. But When I use on CLI its getting Class 'Jenssegers\Mongodb\Eloquent\Model' not found – omero Jun 17 '20 at 20:14
  • ah okay i saw it is 4.0.0 – Mostafa Hana Jun 17 '20 at 20:22
  • use HybridRelations; to first relational Model too. Another suggestion is to add Connection name in both mysql and MongoDB Model classes when they have relations together even when on of them have default Connection name, This will cause problem if you do not in some situations. – Mostafa Hana Jun 17 '20 at 20:32
  • This is a tutorial for using redis with MongoDb https://epsagon.com/blog/development/using-redis-to-optimize-mongodb-queries/ – Mostafa Hana Jun 17 '20 at 20:35
  • Thanks but this is not releated my problem. – omero Jun 18 '20 at 09:59