ashattack
ashattack
FFilament
Created by Vazaios on 5/9/2024 in #❓┊help
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.
return $query
->where(function ($query) use ($categoriesIds, $overrideIds) {
$query->where('variant_type', VariantType::Base->value)
->where(function ($query) use ($categoriesIds, $overrideIds) {
$query->where(function ($query) {
$query->where('variationable_type', Product::class)
->where('variationable_id', $this->getOwnerRecord()->id);
})->orWhere(function ($query) use ($categoriesIds, $overrideIds) {
$query->where('variationable_type', Category::class)
->whereIn('variationable_id', $categoriesIds)
->whereNotIn('id', $overrideIds);
});
});
});
return $query
->where(function ($query) use ($categoriesIds, $overrideIds) {
$query->where('variant_type', VariantType::Base->value)
->where(function ($query) use ($categoriesIds, $overrideIds) {
$query->where(function ($query) {
$query->where('variationable_type', Product::class)
->where('variationable_id', $this->getOwnerRecord()->id);
})->orWhere(function ($query) use ($categoriesIds, $overrideIds) {
$query->where('variationable_type', Category::class)
->whereIn('variationable_id', $categoriesIds)
->whereNotIn('id', $overrideIds);
});
});
});
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
FFilament
Created by GizaRex on 4/17/2024 in #❓┊help
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:
$yourModelInstance->addMedia($pathToFile)
->withCustomProperties([
'name' => ['en' => 'English Name', 'fr' => 'Nom Français'],
'alt_text' => ['en' => 'English Alt Text', 'fr' => 'Texte alternatif en français']
])
->toMediaCollection();
$yourModelInstance->addMedia($pathToFile)
->withCustomProperties([
'name' => ['en' => 'English Name', 'fr' => 'Nom Français'],
'alt_text' => ['en' => 'English Alt Text', 'fr' => 'Texte alternatif en français']
])
->toMediaCollection();
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
FFilament
Created by developer on 2/1/2024 in #❓┊help
how to add action buttons to slideOver() footer
Not at my desk right now but see if something like this works:
php
protected function viewRecordAction(): ViewRecord
{
return parent::viewRecordAction()
->modalContent(...)
->modalActions([
ButtonAction::make('yourCustomAction')
->label('Custom Action')
->action('customActionMethod'),
// Add more buttons as needed
]);
}
php
protected function viewRecordAction(): ViewRecord
{
return parent::viewRecordAction()
->modalContent(...)
->modalActions([
ButtonAction::make('yourCustomAction')
->label('Custom Action')
->action('customActionMethod'),
// Add more buttons as needed
]);
}
7 replies
FFilament
Created by ashattack on 1/26/2024 in #❓┊help
Sometimes Vendor CSS (and JS) are not found after installing
@awcodes Will do that! Ty for the support
7 replies
FFilament
Created by ashattack on 1/26/2024 in #❓┊help
Sometimes Vendor CSS (and JS) are not found after installing
@awcodes thanks for taking the time. Yes sir, both the database scheduler (v2.0.2) and slim scrollbar (v2.0.0) both lists v3 compatibility/support.
7 replies
FFilament
Created by ashattack on 12/4/2023 in #❓┊help
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?
refresh: [
'app/Filament/Resources/**/*.php'
]
refresh: [
'app/Filament/Resources/**/*.php'
]
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
FFilament
Created by ashattack on 11/16/2023 in #❓┊help
How do I create a custom Table Action
I got it working by doing this - sure it works but is this the correct way?
public static function make($name = 'manage'): static
{
return parent::make($name)
->url(fn ($record): string => url("/admin/storefront/{$record->getKey()}/manage"))
->label('Manage Workers');
}
public static function make($name = 'manage'): static
{
return parent::make($name)
->url(fn ($record): string => url("/admin/storefront/{$record->getKey()}/manage"))
->label('Manage Workers');
}
Update: Minor refactor or route:
public static function make($name = 'manage'): static
{
return parent::make($name)
->url(fn ($record): string => StorefrontResource::getUrl('manage', ['record' => $record->getKey()]))
->label('Manage Workers');
}
public static function make($name = 'manage'): static
{
return parent::make($name)
->url(fn ($record): string => StorefrontResource::getUrl('manage', ['record' => $record->getKey()]))
->label('Manage Workers');
}
4 replies
FFilament
Created by ashattack on 11/9/2023 in #❓┊help
How to have a dehydrated function in edit operation but not in create operation
@awcodes that's the attitude! Thank you ❤️
14 replies
FFilament
Created by ashattack on 11/9/2023 in #❓┊help
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
FFilament
Created by ashattack on 11/9/2023 in #❓┊help
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
->dehydrated(function (?array $state, ?Model $user,string $operation){
if(is_null($user)){
return true;
}
if($operation === 'edit'){
//check if role ID is same as whats in the db
$initialRoles = $user->roles->pluck('id');
$stateRole = current($state);
//ray($initialRoles, $stateRole);
$hasChanged = $initialRoles !== $stateRole;
if(!$hasChanged){
//if changed, prevent field from being returned by dehydrate(false)
return false;
}
}
return true;
})->required(self::isCreating())
->dehydrated(function (?array $state, ?Model $user,string $operation){
if(is_null($user)){
return true;
}
if($operation === 'edit'){
//check if role ID is same as whats in the db
$initialRoles = $user->roles->pluck('id');
$stateRole = current($state);
//ray($initialRoles, $stateRole);
$hasChanged = $initialRoles !== $stateRole;
if(!$hasChanged){
//if changed, prevent field from being returned by dehydrate(false)
return false;
}
}
return true;
})->required(self::isCreating())
14 replies
FFilament
Created by ashattack on 11/9/2023 in #❓┊help
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
FFilament
Created by ashattack on 11/9/2023 in #❓┊help
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). 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:
Select::make('roles')
->relationship('roles','name',self::getRoleOrder())
->preload()->searchable()->label('Primary User Role')->default('Restricted')
//Only have the following dehydrated function run on edit page - not on create
->dehydrated(function (?array $state, ?Model $user,string $operation){
if($operation === 'edit'){
//check if role ID is same as whats in the db
$initialRoles = $user->roles->pluck('id');
$stateRole = current($state);
//ray($initialRoles, $stateRole);
$hasChanged = $initialRoles !== $stateRole;
if(!$hasChanged){
//if changed, prevent field from being returned by dehydrate(false)
return false;
}
}
return true;
})->required(self::isCreating())
Select::make('roles')
->relationship('roles','name',self::getRoleOrder())
->preload()->searchable()->label('Primary User Role')->default('Restricted')
//Only have the following dehydrated function run on edit page - not on create
->dehydrated(function (?array $state, ?Model $user,string $operation){
if($operation === 'edit'){
//check if role ID is same as whats in the db
$initialRoles = $user->roles->pluck('id');
$stateRole = current($state);
//ray($initialRoles, $stateRole);
$hasChanged = $initialRoles !== $stateRole;
if(!$hasChanged){
//if changed, prevent field from being returned by dehydrate(false)
return false;
}
}
return true;
})->required(self::isCreating())
14 replies
FFilament
Created by ashattack on 11/7/2023 in #❓┊help
The ideal way to setup permissions
You as well kind sir!
7 replies
FFilament
Created by ashattack on 11/7/2023 in #❓┊help
The ideal way to setup permissions
@Alex Six all I needed to know - thank you and I love you ❤️
7 replies