Tenancy for laravel & File upload component
Hello,
I'm running into an issue that I can't seem to figure out why it's happening.
I use Tenancy for Laravel in my application for multi-tenant capabilities. I have a resource, with a form that contains a file upload. But for some reason, when trying to upload a file, I get the following error:
base table or view not found: 1146 Table 'main_db.users' doesn't exist
I'm confused about why it's trying to access the user's table, and even more so why it's using the central database main_db
rather than the tenant's database. Does anyone know why this is happening?Solution:Jump to solution
Ah @Dennis Koch so I did find it, livewire configures it on temp file uploads:
in
livewire.php
config file...26 Replies
Did you set the tenant middlewares for Livewire requests?
I did 😦
Hm, weird. I guess the Filament middleware is set, otherwise you would have had other issues.
You mean having the tenancy middleware on the panel?
Also, any idea why it would be trying to read the Users model upon fileupload? Im seriously struggeling with debugging this one 😂
Anything special with your FileUpload?
Also, any idea why it would be trying to read the Users model upon fileupload? Im seriously struggeling with debugging this one 😂Authentication
You mean having the tenancy middleware on the panel?Yes.
Not really..
Can you share the stack trace via Flare?
I do have a custom create action, which implements the
using()
method but that would only be hit post creation. This is happening upon completing of the upload already
Flare
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sapphireportal.users' doesn't exist (Connection: central, SQL: select * from
users
where id
= 1 limit 1) - The error occurred at https://mike.sapphireportal.test/livewire/upload-file?expires=1703762991&signature=367d29b3b740cecff1d062b4d16a1b11dd68ca3dad799cd0700e2a6640d7de52Can you maybe try a new super simple form with just the upload? Just to make sure
sure
Do you have a
throttle
in your web middleware group?So i've created a completely new resource + model, and only included a fileupload component, getting the same error
You don't have
universal
as a middleware as in the docsNo throttling set on web
Ye i just removed it for testing, it was there before, though the universal middleware is an empty array in Kernel so doesnt seem to really be doing anything
I will re-add it just incase though
Did you follow this: https://tenancyforlaravel.com/docs/v3/features/universal-routes
But yeah. Universal routes shouldn't be the issue here.
Looking at your stack trace, the error comes from the
ThrottleRequests
middlewareHmm, interestingly I do see the throttle middleware applied in that flare debug info, so it must be called somewhere somehow
Can you share your
web
middleware group?
And:
Also, the panel middelware itself:
What made you conclude that btw? It's weird that the throttle middleware is being included in the request, I cant seem to find anywhere that is being set for this route :/ Trying to figure that out to disable it and test
Solution
Ah @Dennis Koch so I did find it, livewire configures it on temp file uploads:
in
livewire.php
config fileAfter changing that middleware to not include it, it seems to do the trick 🙂 Now getting a 422 error on file upload size, so I think that fixed the issue I was having 😄
If I may ask, just for my own learning, how did you end up concluding it was the throttling from that stack trace? I did not conclude that at all.
Changed max size, upload returning success now, ty so much @Dennis Koch, you've saved me a lot of time ❤️
Nice. Glad to help
I'm guessing it was because it was listed in the Vendor Frames and proceeded into the file further than just hitting a return($next). It's mentioned twice, which makes it stand out a little.
Sorry, I missed your question. But Dr. Byte already answered. I opened the collapsed steps and went through them until there was something helpful 😅
Makes sense, ty for the info 😄