ashattack
Modify Relation Manager query and get data that are not only related to ownerRecord
It likely doesn't work due to the
orWhere
broadening the scope of the query more than intended. Could even result in unexpected records being included in the query which could result in why filament has issues with identifying each record uniquely in the table.
Naively, you could wrap your conditions in a more controlled manner - something like the following where all conditions are encapsulated within a single where
clause and grouped the conditions related to the categories with an additional nested orWhere
which should ensure all the variations (directly attached to the product or its categories) are filtered under the same conditions.
It's a bit ugly though and hard to maintain. Someone else here may have a better approach.
The above code should now check the following:
1. If the variant type is base and the variationable type is Product and the variationable id is the owner record id.
2. If the variant type is base and the variationable type is Category and the variationable id is in the categories ids and the id is not in the override ids.3 replies
What is the best approach?
I'll probably encounter something like this as well soon, perhaps this can help you in the right direction. Say you're using spatie media library, and say you've set up the media library correct - i'd add the
Translatable
, HasMedia
and InteractsWithMedia
to the relevant model. The model should contain a protected $translatable = ['name', 'alt_text']
with your fields.
I'm unsure if spatie/laravel-medialibrary
directly supports translations for media attributes as I haven't personally used it yet. But you could extend the media libraries functionality through custom properties to the media item that you can translate like:
https://spatie.be/docs/laravel-medialibrary/v11/advanced-usage/using-custom-properties
Then modify the filament resource to accommodate the custom form field to allow them to input translations or not.
You should be able to acces the translation in the view or other like so:
$mediaItem->getCustomProperty('name')['en']; // Access English name
You could replace the 'en' or whatever with something dynamic of course.3 replies
After moving resources into a 'shared' directory - browser sync refresh during dev doesn't occur
Ended up going into
vite.config.js
and changing refresh: true
to specify the new directory - it now seems to be working. I'm just curious why I had to do this / if this is the correct way of asserting the autoload?
Edit: it only reloads in the admin panel, in my tenant panel nothing refreshes for this resource?
Edit2 - Fixed it: Created a new theme, and in the tailwind.config.js
I added the shared directory - it now works: '.app/Filament/Resources/**/*.php',
4 replies
How to have a dehydrated function in edit operation but not in create operation
Sorry there, I really do appreciate your patience. Your gut is right - initially I thought I had to dehydrate the roles field since I had a session reset error and added the dehydrate function so that if the role of the user in the database didn't change from what was in the field - to not send the role back to the server...
However the true reason for that was because my chrome autofilled my password in the Edit page on my frontend even though ->autocomplete for password field was set to false. That let me assume it was due to the role being re-assigned - but it turns out it was because it reset my password even though it was the same because my chrome injected my saved password onto the user-edit form - something that would only happen if the logged in admin edits its own user if their chrome browser happened to autofill the password field faceplam....
The dehydrate ended up working on edit user, but then it failed when creating a user...in my incognito browser - which conveniently caused chrome not to auto inject the password causing me to not realize what the actual problem was...
Turns out I spent over an hour trying to debug the dehydrate function when I didn't even need it 😢 At least I learned some stuff. Thank you and sorry for wasting your time!
14 replies
How to have a dehydrated function in edit operation but not in create operation
My latest attempt - I thought ?$model $user if not instantiable - would return null.
Target [Illuminate\Database\Eloquent\Model] is not instantiable.
Type Illuminate\Contracts\Container\BindingResolutionException
14 replies
How to have a dehydrated function in edit operation but not in create operation
@awcodes just checked I believe so! When I do
->dehydrated(function (string $operation){
and dd/ray($operation)
it does output create
.
However if i include ?Model $user
in the dehydrated function, it will only work when I'm editing an existing user. When i create a new user and hit create user
it will perform an error because $user
can't be instantiated because I believe it assumes it exists, which it doesn't if on the create operation.14 replies
How to have a dehydrated function in edit operation but not in create operation
Hi @awcodes - thank you for your response and helping me!
So the logic for dehydrate is only needed on the Edit page for Users. So even if I inject the $operation, I will get an error because the dehydrate function contains a parameter that only exists for users that have been already created (i.e when you edit a user).
Here is how I injected the operation per your suggestion which threw the error:
Target [Illuminate\Database\Eloquent\Model] is not instantiable.
Since on create operation there is no $user model because the user hasn't been created yet.
->dehydrated(function (?array $state, ?Model $user,string $operation){
Any way I could accomplish something equivalent to wrapping the ->dehydrate() around an ifOperation('edit') == true
?Here is how I injected the operation per your suggestion which threw the error:
14 replies