JanV
JanV
FFilament
Created by JanV on 6/21/2024 in #❓┊help
How to access an uploaded file without a resource
The problem was the chained directory; without it, the audio property was accessible with a file name. This way, I could access the uploaded file via the temp directory and move it based on my needs so far. There should be an easier way. I do not have a perfect solution, but it works for now. Thanks, Ross, for your alternative solution! I'm going to try it out, too.
15 replies
FFilament
Created by JanV on 6/21/2024 in #❓┊help
How to access an uploaded file without a resource
Thanks guys! Still no success This is the custom page
<?php

namespace App\Filament\App\Pages;

use Filament\Forms\Components\FileUpload;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Pages\Page;
use Illuminate\Support\Facades\Log;

class AudioRecord extends Page implements HasForms {

protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.app.pages.audio-record';

public array $audio;

public function form(Form $form): Form
{
return $form->schema([
FileUpload::make('audio')
->id('audio')
->directory('audio'),
]);
}

public function save(): void
{
Log::debug('submit');

$state = $this->form->getState();

Log::debug('path', [$state]);
dd($state);
}
}
<?php

namespace App\Filament\App\Pages;

use Filament\Forms\Components\FileUpload;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Pages\Page;
use Illuminate\Support\Facades\Log;

class AudioRecord extends Page implements HasForms {

protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.app.pages.audio-record';

public array $audio;

public function form(Form $form): Form
{
return $form->schema([
FileUpload::make('audio')
->id('audio')
->directory('audio'),
]);
}

public function save(): void
{
Log::debug('submit');

$state = $this->form->getState();

Log::debug('path', [$state]);
dd($state);
}
}
This is the form component
<x-filament-panels::page>
<form wire:submit="save" class="space-y-6">
{{ $this->form }}
<x-filament::button type="submit">
Transcribe
</x-filament::button>
</form>
</x-filament-panels::page>
<x-filament-panels::page>
<form wire:submit="save" class="space-y-6">
{{ $this->form }}
<x-filament::button type="submit">
Transcribe
</x-filament::button>
</form>
</x-filament-panels::page>
As soon as I select a file in from the drop-zone/field, it is automatically uploaded to the server as I can see. As soon I hit the button, the state and file is empty. What am I doing wrong?
15 replies
FFilament
Created by JanV on 6/21/2024 in #❓┊help
How to access an uploaded file without a resource
Thanks for your reply. What do you mean with "run getState()"? Do you mean call the method like this?
public function form(Form $form): Form
{
return $form->schema([
FileUpload::make('audio')
->id('audio')
->directory('audio')
->getState(),
]);
}
public function form(Form $form): Form
{
return $form->schema([
FileUpload::make('audio')
->id('audio')
->directory('audio')
->getState(),
]);
}
I am new to filament so bear with me. So the question is, to be more specific, how and where can I access the uploaded file within my custom page?
15 replies
FFilament
Created by JanV on 6/20/2024 in #❓┊help
Revert ToggleColumn State after failed Validation
Update: throwing the Halt() exception doesn't work. The ValidationException kept the toggle old state! Thanks @Vp
9 replies
FFilament
Created by JanV on 6/20/2024 in #❓┊help
Revert ToggleColumn State after failed Validation
I see, I'll try this approach. Thanks mate! Will give an update here as soon I have progress.
9 replies
FFilament
Created by JanV on 6/20/2024 in #❓┊help
Revert ToggleColumn State after failed Validation
I also tested this
ToggleColumn::make('is_active')
->beforeStateUpdated(function ($record, $state){
$state = false;
$record->is_active = false;
})
ToggleColumn::make('is_active')
->beforeStateUpdated(function ($record, $state){
$state = false;
$record->is_active = false;
})
` Just to see if the hook manipulates the state, but still the record is updated with the user input, instead of my manually assigned value.
9 replies
FFilament
Created by JanV on 6/20/2024 in #❓┊help
Revert ToggleColumn State after failed Validation
This is the column.
ToggleColumn::make('is_active')
->rules(function (Shop $record, $state, Set $set) {
if ($state === false) {
if ($record->isPrintlounge()) {
return [new CanActivatePrintloungeIntegrationRule(shop: $record)];
}
}
return [];
})`
ToggleColumn::make('is_active')
->rules(function (Shop $record, $state, Set $set) {
if ($state === false) {
if ($record->isPrintlounge()) {
return [new CanActivatePrintloungeIntegrationRule(shop: $record)];
}
}
return [];
})`
I tried beforeStateUpdated() but wanted to use rules(), so the record is not updated if the validation fails. As I understand from the documentation
ToggleColumn::make()
->beforeStateUpdated(function ($record, $state) {
// Runs before the state is saved to the database.
})
->afterStateUpdated(function ($record, $state) {
// Runs after the state is saved to the database.
})
ToggleColumn::make()
->beforeStateUpdated(function ($record, $state) {
// Runs before the state is saved to the database.
})
->afterStateUpdated(function ($record, $state) {
// Runs after the state is saved to the database.
})
` The life cycle hook can manipulate the state before or after the record is saved to the DB. But a re-rendering or state binding isn't possible in the list view. May be I don't see the point, yet.
9 replies
FFilament
Created by JanV on 1/3/2024 in #❓┊help
Line Chart not displayed caused by Alpine Error Exception
Ok got it solved. An additional array bracket was missing! 🤦
'datasets' => [
[ // <--- this one!!!
'label' => 'Bestellungen',
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
],
],
'labels' => $data->map(fn (TrendValue $value) => $value->date),
'datasets' => [
[ // <--- this one!!!
'label' => 'Bestellungen',
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
],
],
'labels' => $data->map(fn (TrendValue $value) => $value->date),
4 replies