titoshadow
titoshadow
FFilament
Created by titoshadow on 10/15/2024 in #❓┊help
Change uploaded file permissions
I'm uploading a file (ssh_key) with a FileUpload element, in my Resource. However, I would like to make sure the permissions for the uploaded file are 0600, but I'm not being able to do so with "afterStateUpdated" method, which I though was the way to go, like this:
->afterStateUpdated(function ($state) {
if ($state instanceof UploadedFile) {
$filePath = $state->hashName();

if (Storage::disk('ssh_keys')->exists($filePath)) {
$absolutePath = Storage::disk('ssh_keys')->path($filePath);
chmod($absolutePath, 0600);
}
}
})
->afterStateUpdated(function ($state) {
if ($state instanceof UploadedFile) {
$filePath = $state->hashName();

if (Storage::disk('ssh_keys')->exists($filePath)) {
$absolutePath = Storage::disk('ssh_keys')->path($filePath);
chmod($absolutePath, 0600);
}
}
})
This example fails to set the file permissions, since it seems not to be able to find it. What would be the best approach to achieve this? "ssh_keys" disk is a local folder, inside the app directories.
7 replies
FFilament
Created by titoshadow on 9/19/2024 in #❓┊help
InfoList max width
How can I make my InfoList, which I'm defining in my ModelResource, take the screen whole width, as in MaxWidth::Full ?
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
TextEntry::make('host.name'),
TextEntry::make('event_type.name'),
TextEntry::make('timestamp'),
KeyValueEntry::make('data')
->label('Details')
->keyLabel('Key')
->valueLabel('Value')
->extraAttributes(['style' => 'word-wrap: anywhere'])
->getStateUsing(function (Event $record): array {
$details = [];
foreach ($record->data as $key => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$details[$k] = match (true) {
is_array($v) => json_encode($v),
default => $v,
};
}
}
}
ksort($details);

return $details;
}),
])
->columns(1)
->inlineLabel();
}
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
TextEntry::make('host.name'),
TextEntry::make('event_type.name'),
TextEntry::make('timestamp'),
KeyValueEntry::make('data')
->label('Details')
->keyLabel('Key')
->valueLabel('Value')
->extraAttributes(['style' => 'word-wrap: anywhere'])
->getStateUsing(function (Event $record): array {
$details = [];
foreach ($record->data as $key => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$details[$k] = match (true) {
is_array($v) => json_encode($v),
default => $v,
};
}
}
}
ksort($details);

return $details;
}),
])
->columns(1)
->inlineLabel();
}
15 replies
FFilament
Created by titoshadow on 8/24/2024 in #❓┊help
Reuse infolist modal from resource on Notification view action
Is it possible to show an infolist modal from a Resource I have already defined ? I'm sending a notification to some user, with a "More details" button, and I would like to know if this is easily achievable, or I have to build the infolist separately.
9 replies
FFilament
Created by titoshadow on 8/2/2024 in #❓┊help
Custom datetime filter within relation
I am building a table for an Alert model, whose timestamp is found through a 'timestamp' column from a related model (event), and I'm trying to get a filter on that, like this:
Filter::make('event.timestamp')
->form([
DateTimePicker::make('event.time_from')
->seconds(false),
DateTimePicker::make('event.time_until')
->seconds(false),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['time_from'],
fn (Builder $query, $date): Builder => $query->whereDate('timestamp', '>=', $date),
)
->when(
$data['time_until'],
fn (Builder $query, $date): Builder => $query->whereDate('timestamp', '<=', $date),
);
})
Filter::make('event.timestamp')
->form([
DateTimePicker::make('event.time_from')
->seconds(false),
DateTimePicker::make('event.time_until')
->seconds(false),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['time_from'],
fn (Builder $query, $date): Builder => $query->whereDate('timestamp', '>=', $date),
)
->when(
$data['time_until'],
fn (Builder $query, $date): Builder => $query->whereDate('timestamp', '<=', $date),
);
})
However, I get an error pointing 'time_from' and 'time_until' indexes do not exist in $data, which seems correct since $data is completely empty. What I'm missing in between? Why is $data empty?
4 replies