简体   繁体   中英

Login with Facebook using Sentry in Laravel

I am facing a problem as the one posted here

The problem is this piece of code

$profile = $user->profiles()->save($profile);

which results in this error

Call to undefined method Illuminate\Database\Query\Builder::profiles()

I tried to do what was suggested here

but it didn't work for me. It seems the problem has been solved in a link provided which no longer works.

I wrote my question briefly since the same question has been asked by the user in the link I gave. I will appreciate any help. Thanks

Sentry provides their own User model. If you would like to add relationships to the User, you will need to extend Sentry's User model and update the Sentry config to point to your new User model.

First, create your User model which extends the Sentry User model:

<?php
use Cartalyst\Sentry\Users\Eloquent\User as SentryUserModel;

class User extends SentryUserModel
{
    public function profiles()
    {
        return $this->hasMany('Profile');
    }
}

Next, update the Sentry config to look at your User model instead of the default Sentry User model. To do this, publish the Sentry config file:

php artisan config:publish cartalyst/sentry

Once published, open the app/config/packages/cartalyst/sentry/config.php file. Update the 'users'.'model' value to use your new User model. For example:

'model' => 'User', // assumes non-namespaced custom User model

Sentry will now use your custom User model created above, with the defined relationships.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM