mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/docs/drivers/php/laravel-mongodb/
MIT License
7.01k stars 1.43k forks source link

Laravel 5.3: Call to a member function supportsSchemaTransactions() on null #999

Closed ahmadazimi closed 6 years ago

ahmadazimi commented 8 years ago

Hi there,

I've just upgraded to Laravel 5.3 and also upgraded laravel-mongodb to 3.1.1. Now when I'm trying to migrate the following error occurred:

PHP Fatal error:  Call to a member function supportsSchemaTransactions() on null in /private/var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php on line 378

I've set protected $connection = 'mongodb'; in my migration class.

BTW: up() method never fired, the error occurred before it I think.

ahmadazimi commented 8 years ago

I've just open commented on Laravel issue [https://github.com/laravel/framework/issues/15892#issuecomment-255517921] They said the similar problem was fixed before but work in my case!

laravel version: 5.3.19 jenssegers/laravel-mongodb version: 3.1.1

rasmusdencker commented 8 years ago

+1. Rolled back to Laravel v5.3.18, which works.

ahmadazimi commented 8 years ago

@ellej16 make a comment on that Laravel issue:

As far as I checked jensessegers/laravel-mongodb's source code, it's missing a few key methods/attributes introduced by this particular PR: #15780 . If I remember correctly, one of those are: getSchemaGrammar() and useDefaultSchemaGrammar() on Connection.php (With this being the culprit behind your troubles).

Is there any chance to fix it here?

kofi1995 commented 8 years ago

@ahmadazimi Below is the fix to your issue:

Go to Connection.php which can be found in the Mongodb folder of this package and add these changes:

1) Add use Jenssegers\Mongodb\Schema\Grammar; right below the use MongoDB\Client;.

2) Inside the public function __construct(array $config) function, add $this->schemaGrammar = new Grammar();. It can come before any other code in the function.

Now head over to the Schema folder and create a new file called Grammar.php. The file should contain this:

<?php
namespace Jenssegers\Mongodb\Schema;

use Illuminate\Database\Schema\Grammars\Grammar as BaseGrammar;
/**
 * Class Grammar
 *
 * @package Moloquent\Schema
 */
class Grammar extends BaseGrammar
{
}

I found this fix in the moloquent fork of this package (https://github.com/moloquent/moloquent). Hope this helps you.

ahmadazimi commented 8 years ago

Thank you @kofispaceman I think I should switch to https://github.com/moloquent/moloquent ;-)

jenssegers commented 8 years ago

Was this fixed in the last Laravel release, or still an issue?

ahmadazimi commented 8 years ago

@jenssegers using Laravel v5.3.21 and jenssegers/mongodb v3.1.1

and still this is an issue!

jenssegers commented 8 years ago

Can you try the master branch?

kofi1995 commented 8 years ago

@jenssegers Looks like it has been fixed in the master branch. Thanks!

ahmadazimi commented 8 years ago

@jenssegers Looks like it has been fixed in the master branch.

Thanks.

ahmadazimi commented 7 years ago

@jenssegers when we can have it in stable channel?

jenssegers commented 7 years ago

Will do this now