Yasser
Yasser
FFilament
Created by Yasser on 12/20/2023 in #❓┊help
Disable Validation for other locales
Hello everyone, We have been looking for a while now.... Context - Several Resources, Translatable (Using Filament plugins, json columns and Spatie translatable) - Our other locales are 'optional' Issue The first time a field is filled (edit record), the validation triggers on the forms for the other locales. Question Is there a way to ignore any validation on the forms of the 'non' active locale. Or , to somehow (before validation) Fill the other forms's data with the default locale ones if they are empty ? Extra During my debugging I also found a qwerk in:
// This trait ->
Filament\Resources\Pages\EditRecord\Concerns\Translatable

// This Method ->
public function save(bool $shouldRedirect = true):void
{
// ... Code
// $this->activeLocale tends to return null if using the default locale
$originalActiveLocale = $this->activeLocale;
// ... Code
// If my active locale = 'en' it's still included
$otherTranslatableLocales = Arr::except($this->getTranslatableLocales(), $originalActiveLocale);
// Replacing this line with the equivalent?! does get me what's expected
$otherTranslatableLocales = array_filter(fn($locale)=>$locale!==$originalActiveLocale, $otherTranslatableLocales);
}
// This trait ->
Filament\Resources\Pages\EditRecord\Concerns\Translatable

// This Method ->
public function save(bool $shouldRedirect = true):void
{
// ... Code
// $this->activeLocale tends to return null if using the default locale
$originalActiveLocale = $this->activeLocale;
// ... Code
// If my active locale = 'en' it's still included
$otherTranslatableLocales = Arr::except($this->getTranslatableLocales(), $originalActiveLocale);
// Replacing this line with the equivalent?! does get me what's expected
$otherTranslatableLocales = array_filter(fn($locale)=>$locale!==$originalActiveLocale, $otherTranslatableLocales);
}
3 replies
FFilament
Created by Yasser on 10/8/2023 in #❓┊help
SelectColumn - Dynamic options and Icons
Hello there, once again I am enjoying myself in Filament 😄 I am trying to create a SelectColumn that allows control over the status of a Post I tried to add in comments what I am trying to do: - I would love to have some Icons instead of the strings at the options - I would really like the placeholder to be disabled, yet show the current status based on my logic Should I use an actiongroup instead ?
Tables\Columns\SelectColumn::make('status')
->options(
[
'publish' => 'Publish',//I would love to add an icon here and change the color
'unPublish' => 'UnPublish',
'markAsFeatured' => 'Feature',
'unmarkAsFeatured' => 'Unfeature'
]
)->updateStateUsing(function ($state, $record) {
switch ($state) {
case 'publish':
$record->publish();
break;
case 'unPublish':
$record->unpublish();
break;
case 'markAsFeatured':
$record->markAsFeatured();
break;
case 'unmarkAsFeatured':
$record->unmarkAsFeatured();
break;
}
}
)->disableOptionWhen(
function (string $value,$record): bool {
return match ($value) {
'publish' => $record->isDraft(),
'unPublish' => $record->isPublished(),
'markAsFeatured' => !$record->isFeatured(),
'unmarkAsFeatured' => $record->isFeatured(),
default => false,
};
}
)->placeholder(function ($state, $record) {
if ($record->trashed()) {
return 'heroicon-s-trash';
}
if ($record->isFeatured()) {
return 'heroicon-s-star';
}
if ($record->isPublished()) {
return 'heroicon-s-globe-europe-africa';
}
if ($record->isDraft()) {
return 'heroicon-s-pencil';
}
return 'heroicon-s-question-mark-circle';
})
->disabled(fn($state, $record) => $record->trashed()),
Tables\Columns\SelectColumn::make('status')
->options(
[
'publish' => 'Publish',//I would love to add an icon here and change the color
'unPublish' => 'UnPublish',
'markAsFeatured' => 'Feature',
'unmarkAsFeatured' => 'Unfeature'
]
)->updateStateUsing(function ($state, $record) {
switch ($state) {
case 'publish':
$record->publish();
break;
case 'unPublish':
$record->unpublish();
break;
case 'markAsFeatured':
$record->markAsFeatured();
break;
case 'unmarkAsFeatured':
$record->unmarkAsFeatured();
break;
}
}
)->disableOptionWhen(
function (string $value,$record): bool {
return match ($value) {
'publish' => $record->isDraft(),
'unPublish' => $record->isPublished(),
'markAsFeatured' => !$record->isFeatured(),
'unmarkAsFeatured' => $record->isFeatured(),
default => false,
};
}
)->placeholder(function ($state, $record) {
if ($record->trashed()) {
return 'heroicon-s-trash';
}
if ($record->isFeatured()) {
return 'heroicon-s-star';
}
if ($record->isPublished()) {
return 'heroicon-s-globe-europe-africa';
}
if ($record->isDraft()) {
return 'heroicon-s-pencil';
}
return 'heroicon-s-question-mark-circle';
})
->disabled(fn($state, $record) => $record->trashed()),
1 replies
FFilament
Created by Yasser on 4/13/2023 in #❓┊help
Column Not Found SQL ERROR
Hello there filament, Love the admin panel, tough I have a weird issue I can't figure out. When I sort the visible 'Venue names' I get an SQL error saying Column not found. I get the following error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'questions.venue_id' in 'where clause'
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'questions.venue_id' in 'where clause'
I believe the query it fails on is:
select `name` from `venues` where `questions`.`venue_id` = `venues`.`id`;
select `name` from `venues` where `questions`.`venue_id` = `venues`.`id`;
But if I run
SELECT VENUE_ID FROM QUESTIONS;
SELECT VENUE_ID FROM QUESTIONS;
On my database I do get all venue_id returned
17 replies
FFilament
Created by Yasser on 3/7/2023 in #❓┊help
Sending Notifications On a Filament Page
Hello Everyone, I am in the admin panel trying to send a notification, I saw someone else do this on github
public function updatePassword(): void
{
//New Syntax ?
Notification::make()
->title('Saved successfully')
->icon('heroicon-o-document-text')
->iconColor('success')
->send();
//Old Syntax ?
$this->notify('danger', "{$this->new_password} seems super secure!");
}
public function updatePassword(): void
{
//New Syntax ?
Notification::make()
->title('Saved successfully')
->icon('heroicon-o-document-text')
->iconColor('success')
->send();
//Old Syntax ?
$this->notify('danger', "{$this->new_password} seems super secure!");
}
This is a method I trigger from the form, tough when I open my console I see the following Error:
Alpine: Cannot reference "$wire" outside a Livewire component.
Alpine: Cannot reference "$wire" outside a Livewire component.
Any Ideas on how to fix this ? - The page has multiple forms and multiple form actions
37 replies
FFilament
Created by Yasser on 3/7/2023 in #❓┊help
Reverify Email when changed
Hello everyone, I am quite new to filament, I am trying to add a page where my Admin users can manage their account. Since I don't want users without a verified email to be able to make changes I want to unverify the email when they change it from the page. Tough I am not sure if this is the way to do it (the breeze controller for example does it quite different) Any input would be appreciated!
public $user;//Storing User here

public function mount()
{
$this->user = auth()->user(); //Getting my user from the available auth
$this->updateProfileForm->fill($this->user->toArray());//I saw this in someone elses code ? is this safe?
}
public function updateProfile(): void
{
//!! This is what I am worried about, is this right ?
if ($this->updateProfileForm->getState()['email'] !== $this->user->email) {
$this->user->email_verified_at = null;
}
$this->user->update($this->updateProfileForm->getState());
$this->notify('success', 'Your information has been updated');
}
public $user;//Storing User here

public function mount()
{
$this->user = auth()->user(); //Getting my user from the available auth
$this->updateProfileForm->fill($this->user->toArray());//I saw this in someone elses code ? is this safe?
}
public function updateProfile(): void
{
//!! This is what I am worried about, is this right ?
if ($this->updateProfileForm->getState()['email'] !== $this->user->email) {
$this->user->email_verified_at = null;
}
$this->user->update($this->updateProfileForm->getState());
$this->notify('success', 'Your information has been updated');
}
Thanks a lot in advance!
14 replies