If you use the out of box Authentication code, it will give you the following error:
FatalErrorException in Builder.php line 1514:
Call to a member function compileSelect() on null
I managed to fix this by doing the follwoing:
In the class that user extends, change the model from the default to the MongoDB Model class and it will work.
I don't know if there is any other suggestions on the proper way to handle this error.
Wow thanks !
I ran into this as well. The proper way to handle the error is not to modify core Laravel files but extend the User.php class that is likely at app/User.php
Inside the file change:
use Illuminate\Foundation\Auth\User as Authenticatable;
to:
use YourApp\Authentication\User as Authenticatable;
Create the file (and folder if necessary) for:
YourAppAuthentication\User.php
Inside that file paste the User.php but modify with your namespace, as follows:
<?php
namespace YourApp\Authentication;
use Illuminate\Auth\Authenticatable;
use Jenssegers\Mongodb\Eloquent\Model as Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements
AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
}
This is the band-aid version and this process should actually probably get worked into the module so you would actually end up editing the User.php to something like (note that this is hypothetical and does not exist):
use Jenssegers\Mongodb\Authentication\User as Authenticatable;
After I made these changes I was able to get through the registration/signup flow with a new record being created in MongoDB. The next hurdle I ran into which is a bigger issue is that the authentication identifier that L5 (5.2.x) is looking for is "id" and the MongoID is _id. By copying the "_id" to "id" in the json/bson on the MongoDB document I was able to force it to work testing, but this was just a test to see if the identifier was being pulled as "id".
I'm looking into options to solve for the _id vs id issue which probably means extending the auth driver for Laravel.
https://github.com/laravel/framework/blob/5.2/src/Illuminate/Auth/GenericUser.php#L34
I will post a follow-up if I'm able to figure out the next piece in this puzzle.
@infernobass7 Do you have sample code from what you mean. Running into the same error. I have a clean install of Laravel 5.2 out of box and have managed to get MongoDB Drivers working but when i add MySQL queries i get this error:
FatalThrowableError in Builder.php line 1514:
Call to a member function compileSelect() on null
@CammoKing I tried your solution but still have the same error coming up. Any other ideas?
@TheeAndre @infernobass7
I will try to get the changes I have made to get auth working for 5.2 forked and a pull request in tonight or sometime tomorrow. Their will need to be some documentation updates as well because you have to add a custom user provider for the driver implementation and also a custom generic user implementation because otherwise it tries to reference the wrong string identifier in the users table.
I will provide an update here asap.
@TheeAndre @infernobass7
Here is the pull request that is in for these updates:
https://github.com/jenssegers/laravel-mongodb/pull/895
This fixes login, logout, and registration for the native Laravel auth. I saw an error with the password reset endpoint which appears to originate from the PasswordBroker class. Probably something needs to be updated there but I don't have time to tackle that at this moment.
The error was: UnexpectedValueException in PasswordBroker.php line 238: User must implement CanResetPassword interface.
If either of you want to test these updates the documentation in the readme is updated with some instructions on my forked repo. You can pull that and symlink in that repo to your vendor, or just temporarily replace the /vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Auth directory, etc (if this is a show stopper for you at this time). Just thinking if you want to keep moving forward while the pull request is awaiting review.
Let me know if you have any issues/need any clarification.
@CammoKing Thank you so much for this. Will test this out and let you know how it goes.
As I stated on an other issue report, I am stuck at the same PasswordBroker bug.
Just need to fix the
'JenssegersMongodbAuthMongoDBAuthServiceProvider',
to
'JenssegersMongodbAuthAuthServiceProvider',
in the docs
@c0h1b4 Thanks for that catch, I looked into it last night and realized the naming snafu in the docs as well. I will get the readme updated and pushed.
Most helpful comment
I ran into this as well. The proper way to handle the error is not to modify core Laravel files but extend the User.php class that is likely at app/User.php
Inside the file change:
use Illuminate\Foundation\Auth\User as Authenticatable;to:
use YourApp\Authentication\User as Authenticatable;Create the file (and folder if necessary) for:
YourAppAuthentication\User.php
Inside that file paste the User.php but modify with your namespace, as follows:
This is the band-aid version and this process should actually probably get worked into the module so you would actually end up editing the User.php to something like (note that this is hypothetical and does not exist):
use Jenssegers\Mongodb\Authentication\User as Authenticatable;After I made these changes I was able to get through the registration/signup flow with a new record being created in MongoDB. The next hurdle I ran into which is a bigger issue is that the authentication identifier that L5 (5.2.x) is looking for is "id" and the MongoID is _id. By copying the "_id" to "id" in the json/bson on the MongoDB document I was able to force it to work testing, but this was just a test to see if the identifier was being pulled as "id".
I'm looking into options to solve for the _id vs id issue which probably means extending the auth driver for Laravel.
https://github.com/laravel/framework/blob/5.2/src/Illuminate/Auth/GenericUser.php#L34
I will post a follow-up if I'm able to figure out the next piece in this puzzle.