New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with model and auth #682

Closed
rubenrios3dids opened this Issue Dec 17, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@rubenrios3dids
Copy link

rubenrios3dids commented Dec 17, 2018

Hello, im have a bit problem with the models and modules.

I have a model User with more functions than User model original.

When i use Auth()->User for get user model, i retrieve the user model global of laravel, i cant call functions of the User model of the module.

Now i use this: \Modules\Chat\User::where('id', Auth()->User()->id)->first() to get the user, but this generate a extra sql query.

you know other form to realize this?

@nWidart

This comment has been minimized.

Copy link
Owner

nWidart commented Dec 20, 2018

Hi, I don't think this is related to this package.
The laravel docs explain how to eager load, to avoid additional queries.

@rubenrios3dids

This comment has been minimized.

Copy link

rubenrios3dids commented Dec 20, 2018

Hi, but when i use Auth::user() this already fetch the user with user model original.

I will like use user from module in auth::user(), i know about eager load, but i cant use that with auth::user for load another user from same table.

If not, I will forget this problem xD

a regards and thx!

@nWidart

This comment has been minimized.

Copy link
Owner

nWidart commented Dec 20, 2018

I think the only way to prevent this extra query, is to get the user id from somewhere else, like from the client sending you the request for example.

@flavius-constantin

This comment has been minimized.

Copy link

flavius-constantin commented Dec 25, 2018

Now i use this: \Modules\Chat\User::where('id', Auth()->User()->id)->first() to get the user, but this generate a extra sql query.

Why you don't try to solve it like this?
\Modules\Chat\User::with('relation')->where('id', auth()->user()->id)->first()

@nWidart

This comment has been minimized.

Copy link
Owner

nWidart commented Jan 9, 2019

I'll close this as there hasn't been a reply in a while, feel free to comment if needed.

@nWidart nWidart closed this Jan 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment