The Right Way to Use Laravel 4 Model Sentry 2 Relationships

I am trying to figure out how to return the relationships that I configured for my User model when using Sentry 2.

Typically, I have a user obtained as follows:

$user = User::find(1);

// get some relation
return $user->profile->profile_name;

However, now that I have Sentry 2, I can get a registered user as follows:

$user = Sentry::getUser();

This way, I can easily access the table usersin my database, but how do I deal with the choice of relationships and methods that I set in my model User.php?

This is similar to clumpsy, not Laravel-ish:

User::find(Sentry::getUser()->id)->profile->wizard_completed;

It seems a little ... back.

Can you guys help me? =)

+4
1

Sentry, :

<?php

use Cartalyst\Sentry\Users\Eloquent\User as SentryModel;

class User extends SentryModel {

    public function profile()
    {
        return hasOne(...);
    }

}

:

php artisan config:publish cartalyst/sentry

Sentry, , Sentry :

'model' => 'User',

:

echo Sentry::getUser()->profile->wizard_completed;
+21

Source: https://habr.com/ru/post/1527776/


All Articles