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

::all() gives PHP Fatal error: Call to a member function compileSelect() on null #901

Closed dpasch01 closed 6 years ago

dpasch01 commented 8 years ago

DB::collection('test_collection')->all(); works fine, but when i use my TestCollection model i get PHP Fatal error: Call to a member function all() on array in \vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php on line 609.

TestCollection model:

namespace App\Models;

use Moloquent;

class TestCollection extends Moloquent{

  protected $connection = 'mongodb';
  protected $collection = 'test_collection ';
  protected static $unguarded = true;

}

TestCollection controller:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Models\TestCollection;

class MongoController extends Controller{

  public function index(Request $request){
    return TestCollection::all();
  }

}
gp187 commented 8 years ago

Are you sure you are extending the correct Model ? Try this in your TestCollection model

use Jenssegers\Mongodb\Eloquent\Model as Moloquent;
kschethan commented 8 years ago

Any update on this? Relations not working for me. Laravel 5.3

FatalErrorException in Builder.php line 613:
Call to a member function all() on array

MySql relations are working fine.

nitinsurana commented 8 years ago

Same error Call to a member function all() on array

nitinsurana commented 8 years ago

Insight -

App\Video::take(10) => Jenssegers\Mongodb\Eloquent\Builder {#714}

DB::collection('video')->take(10) => Jenssegers\Mongodb\Query\Builder {#709

Notice both are returning different objects.

pi0 commented 8 years ago

@nitinsurana please update you composer dependency version to 3.1.0-alpha and do run composer update

kschethan commented 8 years ago

I can confirm that the error is not there in version 3.1.0-alpha. You may close this issue.

nitinsurana commented 8 years ago

@pi0 works, thanks.

alexjose commented 8 years ago

I am still getting the same error in 3.1.0-alpha.

pi0 commented 8 years ago

@alexjose it will certainly work, but if you still have problems you could also try Moloquent :)

Vittalks commented 7 years ago

[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function compileSelect() on null

same issue getting in 3.2 also

Vittalks commented 7 years ago

call any api its throw an error

FatalErrorException in Builder.php line 1581: Call to a member function compileSelect() on null

msankar1991 commented 7 years ago

After composer update getting same error with mongodb