Using Eloquent methods with Sentry

170 Views Asked by At

I'm using Sentry with my Laravel app, and I'm wondering if it's possible to make use of some of the great Eloquent methods while using Sentry to manage my User objects. For example, with Eloquent I can look up a user, and create one if they don't exist, like this:

$user = User::firstOrNew(array('email'=>'[email protected]'));

I would like to accomplish the same thing with Sentry, but from what I can tell, it can't be done out of the box. Instead, I would have to handle an exception like this:

 try{
     $user = Sentry::findUserByLogin('[email protected]');
 }
 catch (Cartalyst\Sentry\Users\UserNotFoundException $e){
     $user = Sentry::createUser(array(
         'email' => '[email protected]'
     ));
 }

The Eloquent method is cleaner and less work, so I'm wondering if there is any way to do that with Sentry.

1

There are 1 best solutions below

0
On

This is working for me:

$user = Sentry::getEmptyUser()->firstOrCreate(array('email'=>'[email protected]'));