modifyQueryUsing breaks ToggleColumn
in the
app/Filament/Resources/FormResource.php
file i set up the table:
if the user is not admin, i want to show their created forms or the forms they are attached to.
the issue is that when i modify the query, if the user is admin, works just fine, but if the user is not admin, if the user toggles the is_active
column, it toggles the last row being shown in the table!
https://filamentphp.com/docs/3.x/panels/resources/listing-records#customizing-the-table-eloquent-query
i think the issue is related to the or
. why? because if i change the orWhere
to a where
, the toggle works fine, but then the query is not the query i want.
im doing something wrong or it's actually a bug?
update:
i also tried it this way. this way makes the toggles to not change
36 Replies
bump
please let me know how should i modify the question so anyone can answer it xd
bump
To me it sounds like the
id
from users
table overwrite the id
of your resource and therefore it toggles the wrong one.
Can you check the resulting SQL query via Debugbar or similar? Maybe a ->select('your_table.*')
helps?sure, 1sec
this is what i tried. i captured what queries are done when i toggle the field
i did it on a record with id 15 but it updated it on the record with id 10
idk if u meant to check this
Can you check the query that loads the table
there is a bunch, not sure if is this one
I am not sure whether the columns from the subquery should leak to the main query, but it feels like they do. If you run that query from a DB-Tool is the form ID overwritten by the users.id?
it is not overwritten:
Hm, weird.
what would u do now? idk what to debug more xD
Turn on Xdebug to check why it's resolving a wrong ID 😅
Does it only happen on the column or also for the actions?
i think only on the toggle column
uff, no clue how to do that, but i guess ill figure it out
But it feels weird to me if it's only the column 🤔
users use it everyday and they havent told me about issues with the row actions
just the toggle
You're about to unlock the secret weapon of fixing things quickly.
What IDE are you using, and what development environment? (Sail/Herd/Valet/DDEV etc)
vscode + herd
macos
secret weapon lets go 😋
i meant, i heard about xdebug but idk why i thought it was not for vscode, like only for phpstorm (idk why xd)
It's straightforward to set up, and once it is set up, it's so powerful for finding out what's actually happening in your application.
thanks 🙏 ill set it up and ill let u know what i find in the table 🔍 🔍 🔍 🔍
oh yeah i used that with java like years ago
Click to the left of a line number to set a breakpoint, where the code will stop executing, then you can manually "step into", which will execute line by line going into any functions and diving deep into the framework, or "step over" which will jump to the next instruction at the same level you're already at.
yesss 🙏
@Tetracyclic i followed the steps. now im on the web.php route file & start the debugger but i get:
not sure why, ill keep investigating. i had to install the vscode extension to debug aswell, not sure if it just will work or i have to configure it aswell
Instead of starting the debugger inside VSCode, you'll want to use a browser plugin that can trigger XDebug
https://chromewebstore.google.com/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc?hl=en
https://addons.mozilla.org/en-GB/firefox/addon/xdebug-helper-for-firefox/
ohh, why?
Running it from within VSCode won't (without a lot of configuration) emulate the browser environment
With one of those extensions you just browse to the page that will trigger your breakpoints and it will communicate with the IDE to start debugging.
then here i dont need a vscode file, no? or i need it anyways?
You still need that configuration in VSCode, I believe. It tells VScode how to listen for the debug session
u sure is available for vscode?
i installed it, enabled it and went to a test route
that route has 2 breakpoints but does nothing, im missing something for sure
I think in Xdebug Helper you'll need to configure the IDE key to be "VSCODE"
(I'm only familiar with using it in PHPStorm, so I'm guessing a bit here)
Oh, apparently that isn't needed:
Tom
Tom McFarlin
Xdebug in Visual Studio Code | Tom McFarlin
Everything that needs to be done to install Xdebug with a Homebrew-based environment and to work with the software within Visual Studio Code.
i have no clue why my vscode button "create a launch.json file" doesnt do anything at all when clicked