-
Notifications
You must be signed in to change notification settings - Fork 142
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
BelongsToTenant not working on user model #45
Comments
I'm having the same problem since upgrading Laravel from 5.2 to 5.3 and switching to Landlord v2 at the same time. |
Does your |
Yes, it does. The difference is that the |
Yes, same to me. Trait in my User model nevertheless not working.
|
Hmm that's really strange. All the trait does is register some global scopes. Is anyone able to provide a test case for me? I can't replicate. |
I'll try to create a test setup tomorrow, thanks for the support! Edit/small update: |
Maybe I have found out what is happening: When I call the middleware with
If the scope is applied later by using a group middleware (via So I think the problem is a combination of the changed behavior in Laravel 5.3 and the issue described in #46. Does someone know a way to access the authenticated user in the global middleware? This would avoid the "booting-problem" I think. |
Did you try to use Landlord v1.0.2? |
Unfortunately only with Laravel 5.2 before the upgrade. In this setup everything worked fine. |
I'm having the same issue, anyone got a resolution? |
Code provided by @mariomka #49 (comment) somehow fixed this issue for me. Now it works on User model. :) |
Anyone has found other solution? |
If anyone can work out the actual reason that @mariomka's solution works, we can try to tackle this once and for all. |
I can confirm that the solution from #49 also works for me. @gustavobissolli Currently I use a workaround in my project, so that I can use the unmodified Landlord release. I have created a second I have created a demo project which shows how the scope changes dependent on the login state. |
@flofloflo You mean that the summary of your solution is that clones the user model to Employee model. Taking into consideration |
@EmadAdly Yes, that's the solution (or workaround) I'm currently using. The repository I posted shows the difference between using |
On Laravel v5.2.45 using Landlord v2.0.5 I can scope the User model by adding |
Did not work out after all. Any solution to this which doesn't involve cloning the User model? |
@patroniton I was accidentally still checkin the DB for the |
Has anyone been able to work out why doing a single scope instead of multiple scopes makes a difference? |
I'm certain there are multiple issues here. I do want to get to the bottom of it, but this thread has gotten too confused. I'm going to close this issue, but if anyone is still having any of these issues:
Please open a new issue with details about exactly where you are calling Thanks! |
Hey Guys,
everything works fine: If I query with
Model::find(123)
on my model and the resource does not belong to the current tenant (set via middleware) the request fails.But: If I query on the User model it does not work. While asking for
User::all()
I get really all results including other customers and while queryingUser::findOrFail()
with an ID which does not belong to the current tenant I get the result .. so everytime working with my user model I have to check if$model->tenant_id == $request->user()->tenant_id
The text was updated successfully, but these errors were encountered: