Search code examples
mongodblaravel-5jenssegers-mongodblaravel-5.5

Laravel 5.5 Mongo DB error


I am developing a Mongo DB app in Laravel 5.5. But getting following error in the package https://github.com/jenssegers/laravel-mongodb.

Declaration of Jenssegers\Mongodb\Eloquent\HybridRelations::belongsToMany($related, $collection = NULL, $foreignKey = NULL, $otherKey = NULL, $relation = NULL) should be compatible with Illuminate\Database\Eloquent\Model::belongsToMany($related, $table = NULL, $foreignPivotKey = NULL, $relatedPivotKey = NULL, $parentKey = NULL, $relatedKey = NULL, $relation = NULL)

Following are the steps I did.

  1. Installed Mongo db and its php extension.
  2. Installed this Laravel package.
  3. Added the service provider
  4. Configured DB
  5. Created the model
  6. And finally
    $user = DB::connection('mongodb')->collection('users')->get();

Solution

  • As far as I know Laravel 5.5 has changed signature of belongsToMany method, so you should wait until this package will be compatible with Laravel 5.5 I see issue about this was already created here: https://github.com/jenssegers/laravel-mongodb/issues/1279