rydurham / Sentinel

A Sentry bridge package for Laravel
http://www.ryandurham.com/projects/sentinel/
317 stars 68 forks source link

How can we get User data? #234

Closed AlexMcowkin closed 6 years ago

AlexMcowkin commented 6 years ago

How can we get User data like id, email and etc?

I need use it in my views!

sorry for the questions but I dont understand how

rydurham commented 6 years ago

Good question. The best way to do this is to use the tools that Laravel itself provides. Once you have published the config files for this package you can edit the sentry config file to tell the Sentry package to use your user model App\User instead of the default Sentry user. (Make sure that your user model is extending the Sentry user class.) From there you can do almost anything:

$user = \App\User::find(1);
echo $user->first_name;
echo $user->second_name;

If you fetch the user object in your controller and pass it to your custom views you should be good to go. You can see examples of how that works in the controllers in this package.

AlexMcowkin commented 6 years ago

thank you

AlexMcowkin commented 6 years ago

how to get current logged in user id?

rydurham commented 6 years ago

This package is a wrapper for the Cartalyst\Sentry package; all of the methods there are available to you in your application.

To determine if a user is currently logged in: Sentry::check() If that method returns true, you can get the user object via Sentry::getUser()

Running getUser() if there is no active session available will throw an exception.

AlexMcowkin commented 6 years ago

yes. I did it already. but thank you. when I will have more free time I will write instruction for russians =)