BuddhaNature
BuddhaNature
FFilament
Created by BuddhaNature on 11/18/2024 in #❓┊help
How can I add a client side error message to FileUpload?
This doesn't address my problem. I can perform all of the server side validations fine and issue custom messages accordingly. In my code example, if a user adds an image larger that 2MB, the validation kicks in on the client side and the file is not uploaded. In the article above, which is good, but not applicable, any file above 2MB would be uploaded and then validated on the server side. What I'm looking to accomplish is to present a message to the user when they attempt to upload a file larger than 2MB on the client side. As is, the validation just causes the "X" button to jiggle which is not obvious.
4 replies
FFilament
Created by BuddhaNature on 9/15/2024 in #❓┊help
In a Table Filter, how can I query a JSON element that is an array instead of a value?
Figured it out:
SelectFilter::make('data->tags')
->label('Tags')
->multiple()
->options(TagEnum::class)
->query(function (Builder $query, array $data): Builder {
return $query->whereJsonContains(
'data->tags',
$data['values']
);
})
SelectFilter::make('data->tags')
->label('Tags')
->multiple()
->options(TagEnum::class)
->query(function (Builder $query, array $data): Builder {
return $query->whereJsonContains(
'data->tags',
$data['values']
);
})
4 replies
FFilament
Created by BuddhaNature on 9/5/2024 in #❓┊help
Will mounting an action keep parameters from being seen by the world?
I posed this question to Chat GPT out of curiosity, and it responded as follows: 2. Use Laravel's Encryption for Sensitive Data If you must send some sensitive data from the client to the server, you can encrypt it using Laravel's encryption facilities (Crypt facade). Here's how you can do that: - Before passing the argument, encrypt it on the server:
use Illuminate\Support\Facades\Crypt;

$encryptedData = Crypt::encrypt($sensitiveData);
$this->mountAction('someAction', ['encryptedData' => $encryptedData]);
use Illuminate\Support\Facades\Crypt;

$encryptedData = Crypt::encrypt($sensitiveData);
$this->mountAction('someAction', ['encryptedData' => $encryptedData]);
- In your action handler, decrypt the data:
public function someAction($encryptedData)
{
$sensitiveData = Crypt::decrypt($encryptedData);
}
public function someAction($encryptedData)
{
$sensitiveData = Crypt::decrypt($encryptedData);
}
14 replies
FFilament
Created by BuddhaNature on 9/5/2024 in #❓┊help
Will mounting an action keep parameters from being seen by the world?
Thank you so much for this conversation. It's really helpful. As a follow up, would encrypting data be considered a bad practice? For example, if I want to pass Superman's secret identity as a public variable, but encrypt it when I call the action and then subsequently decrypt it when I need it?
Action::make($this->name)
// Other stuff
->action(function () {
$this->secretIdentity = Crypt::encryptString('Clark Kent');
$this->mountAction('kryptonAction');
})
Action::make($this->name)
// Other stuff
->action(function () {
$this->secretIdentity = Crypt::encryptString('Clark Kent');
$this->mountAction('kryptonAction');
})
14 replies
FFilament
Created by BuddhaNature on 9/5/2024 in #❓┊help
Will mounting an action keep parameters from being seen by the world?
Oh, wait. That seems like it prevents it from being manipulated, but is still exposed.
14 replies
FFilament
Created by BuddhaNature on 9/5/2024 in #❓┊help
Will mounting an action keep parameters from being seen by the world?
So if I wanted something secret (e.g., Clark's secret identity), the ideal way is to add the #[Locked] attribute?
14 replies
FFilament
Created by BuddhaNature on 9/5/2024 in #❓┊help
Will mounting an action keep parameters from being seen by the world?
Is $this->mountedActionsArguments the best way to get that data or is there a better way?
14 replies
FFilament
Created by BuddhaNature on 9/5/2024 in #❓┊help
Will mounting an action keep parameters from being seen by the world?
I don't need the data on the front end. I just need it to process some stuff on the backend.
14 replies
FFilament
Created by BuddhaNature on 7/23/2024 in #❓┊help
How to pass form data when using replaceMountedAction()
After some trial and error, this gave me the result, I am looking for, but it doens't look like an ideal solution.
TextEntry::make('keyword')
->state(function () {
return $this->mountedActionsArguments[0]['keywords'];
})
TextEntry::make('keyword')
->state(function () {
return $this->mountedActionsArguments[0]['keywords'];
})
2 replies
FFilament
Created by GHOST-117 on 7/10/2024 in #❓┊help
I want to set the time zone of the app according to users timezone
One thing to consider in your panel is to show two times. One local to you and one local to the current order. You can supplement that with a relative time as well.
9 replies
FFilament
Created by GHOST-117 on 7/10/2024 in #❓┊help
I want to set the time zone of the app according to users timezone
All of the output above is the exact same time. If you read By Date, it seems like one time is ahead of another by a day, but that's just a quirk of timezones. If you look at the relative parts, you can see that no matter what the time zone translation is, it's all the exact same moment in time.
9 replies
FFilament
Created by GHOST-117 on 7/10/2024 in #❓┊help
I want to set the time zone of the app according to users timezone
@GHOST-117 A different way to look at it is that the order is being place at the same time as you, but shifted relative to the time zone. Ideally, you want to show time relative to you, not them. You want to show them time relative to them, not you. You can also use human readable relative formats. Here's an example:
use Illuminate\Support\Carbon;

$order = Carbon::createSafe(2024, 7, 9, 12, 0, 0, "UTC");

[
"By Date" => [
"UTC" => $order->timezone("UTC")->toDayDateTimeString(),
"Nashville" => $order->timezone("America/Chicago")->toDayDateTimeString(),
"Fiji" => $order->timezone("Pacific/Fiji")->toDayDateTimeString()
],
"Relative" => [
"UTC" => $order->timezone("UTC")->diffForHumans(),
"Nashville" => $order->timezone("America/Chicago")->diffForHumans(),
"Fiji" => $order->timezone("Pacific/Fiji")->diffForHumans()
],
"Relative, 4 parts" => [
"UTC" => $order->timezone("UTC")->diffForHumans(["parts" => 4]),
"Nashville" => $order
->timezone("America/Chicago")
->diffForHumans(["parts" => 4]),
"Fiji" => $order->timezone("Pacific/Fiji")->diffForHumans(["parts" => 4])
]
];
use Illuminate\Support\Carbon;

$order = Carbon::createSafe(2024, 7, 9, 12, 0, 0, "UTC");

[
"By Date" => [
"UTC" => $order->timezone("UTC")->toDayDateTimeString(),
"Nashville" => $order->timezone("America/Chicago")->toDayDateTimeString(),
"Fiji" => $order->timezone("Pacific/Fiji")->toDayDateTimeString()
],
"Relative" => [
"UTC" => $order->timezone("UTC")->diffForHumans(),
"Nashville" => $order->timezone("America/Chicago")->diffForHumans(),
"Fiji" => $order->timezone("Pacific/Fiji")->diffForHumans()
],
"Relative, 4 parts" => [
"UTC" => $order->timezone("UTC")->diffForHumans(["parts" => 4]),
"Nashville" => $order
->timezone("America/Chicago")
->diffForHumans(["parts" => 4]),
"Fiji" => $order->timezone("Pacific/Fiji")->diffForHumans(["parts" => 4])
]
];
Your output will look like this:
[
"By Date" => [
"UTC" => "Tue, Jul 9, 2024 12:00 PM",
"Nashville" => "Tue, Jul 9, 2024 7:00 AM",
"Fiji" => "Wed, Jul 10, 2024 12:00 AM",
],
"Relative" => [
"UTC" => "1 day ago",
"Nashville" => "1 day ago",
"Fiji" => "1 day ago",
],
"Relative, 4 parts" => [
"UTC" => "1 day 9 hours 31 minutes 22 seconds ago",
"Nashville" => "1 day 9 hours 31 minutes 22 seconds ago",
"Fiji" => "1 day 9 hours 31 minutes 22 seconds ago",
],
]
[
"By Date" => [
"UTC" => "Tue, Jul 9, 2024 12:00 PM",
"Nashville" => "Tue, Jul 9, 2024 7:00 AM",
"Fiji" => "Wed, Jul 10, 2024 12:00 AM",
],
"Relative" => [
"UTC" => "1 day ago",
"Nashville" => "1 day ago",
"Fiji" => "1 day ago",
],
"Relative, 4 parts" => [
"UTC" => "1 day 9 hours 31 minutes 22 seconds ago",
"Nashville" => "1 day 9 hours 31 minutes 22 seconds ago",
"Fiji" => "1 day 9 hours 31 minutes 22 seconds ago",
],
]
9 replies
FFilament
Created by GHOST-117 on 7/10/2024 in #❓┊help
I want to set the time zone of the app according to users timezone
The app's timezone can be changed dynamically in a provider or middleware, but it's not a good idea to do that. The app should represent the timezone of the data, not any single user. When presenting data, you can then present the user's relative time zone based on a helper like ->timezone. Another way to think of this is that the data in the database should be normalized, not relative to any single user.
9 replies
FFilament
Created by BuddhaNature on 6/27/2024 in #❓┊help
When using EditAction in an ActionGroup, how can the icon be removed?
Oooooooooh! That worked. You are my hero.
10 replies
FFilament
Created by BuddhaNature on 6/27/2024 in #❓┊help
When using EditAction in an ActionGroup, how can the icon be removed?
I added that method and have the same result as before.
10 replies
FFilament
Created by BuddhaNature on 6/27/2024 in #❓┊help
When using EditAction in an ActionGroup, how can the icon be removed?
php// Scenario 1

use Filament\Actions\ActionGroup;
use Filament\Actions\EditAction;

public function getHeaderActions(): array
{
return ActionGroup::make([
EditAction::make('edit1')->icon('')->label('One'),
EditAction::make('edit2')->icon(null)->label('Two'),
EditAction::make('edit3')->icon('name-of-icon-that-does-not-exist')->label('Three'),
]);
}

// Scenario 2

use Filament\Tables\Actions\ActionGroup;
use Filament\Tables\Actions\EditAction;

public function getHeaderActions(): array
{
return ActionGroup::make([
EditAction::make('edit1')->icon('')->label('One'),
EditAction::make('edit2')->icon(null)->label('Two'),
EditAction::make('edit3')->icon('name-of-icon-that-does-not-exist')->label('Three'),
]);
}
php// Scenario 1

use Filament\Actions\ActionGroup;
use Filament\Actions\EditAction;

public function getHeaderActions(): array
{
return ActionGroup::make([
EditAction::make('edit1')->icon('')->label('One'),
EditAction::make('edit2')->icon(null)->label('Two'),
EditAction::make('edit3')->icon('name-of-icon-that-does-not-exist')->label('Three'),
]);
}

// Scenario 2

use Filament\Tables\Actions\ActionGroup;
use Filament\Tables\Actions\EditAction;

public function getHeaderActions(): array
{
return ActionGroup::make([
EditAction::make('edit1')->icon('')->label('One'),
EditAction::make('edit2')->icon(null)->label('Two'),
EditAction::make('edit3')->icon('name-of-icon-that-does-not-exist')->label('Three'),
]);
}
10 replies
FFilament
Created by BuddhaNature on 6/27/2024 in #❓┊help
When using EditAction in an ActionGroup, how can the icon be removed?
Neither of these works:
10 replies
FFilament
Created by BuddhaNature on 5/29/2024 in #❓┊help
How can the resource query be modified on an Infolist page?
This is the route I went with. I'd love your thoughts.
public static function getEloquentQuery(): Builder
{
$query = parent::getEloquentQuery()
->withoutGlobalScopes([SoftDeletingScope::class]);

return match (Route::currentRouteName()) {
ViewPageSampeOne::getRouteName() => $query->select(['id', 'name', 'title', 'notes']),
ViewPageSampeTwo::getRouteName() => $query->select(['id', 'name', 'metadata']),
default => $query->select(['id', 'name', 'title']),
};
}
public static function getEloquentQuery(): Builder
{
$query = parent::getEloquentQuery()
->withoutGlobalScopes([SoftDeletingScope::class]);

return match (Route::currentRouteName()) {
ViewPageSampeOne::getRouteName() => $query->select(['id', 'name', 'title', 'notes']),
ViewPageSampeTwo::getRouteName() => $query->select(['id', 'name', 'metadata']),
default => $query->select(['id', 'name', 'title']),
};
}
6 replies
FFilament
Created by BuddhaNature on 5/29/2024 in #❓┊help
How can the resource query be modified on an Infolist page?
Was the above clear @Leandro Ferreira ?
6 replies
FFilament
Created by BuddhaNature on 5/29/2024 in #❓┊help
How can the resource query be modified on an Infolist page?
Let's assume I have this hypothetical table DB table with these fields: id name, string title, string data, json notes, json details, json The resource:
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->withoutGlobalScopes([SoftDeletingScope::class]);
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->withoutGlobalScopes([SoftDeletingScope::class]);
}
The Table on the List Page has the following on the Table component:
->modifyQueryUsing(fn (Builder $query) => $query
->select(['id', 'name', 'title']));
->modifyQueryUsing(fn (Builder $query) => $query
->select(['id', 'name', 'title']));
This limits the scope and doesn't load any of the json data. This work now. On the view page, I'd like to modify the resource query to this:
$query->select(['id', 'name', 'title', 'data'])
$query->select(['id', 'name', 'title', 'data'])
This query includes data, but not notes and details. And then on an additional custom page, I'd like to modify the resource query to this:
$query->select(['id', 'name', 'title', 'notes', 'details'])
$query->select(['id', 'name', 'title', 'notes', 'details'])
This query includes notes and details, but not data. If a DB table with a lot of fields, especially larger fields like TEXT of JSON, I'm trying to limit the scope on a page by page basis.
6 replies