John
John
FFilament
Created by Chriis on 10/26/2023 in #❓┊help
Using $record into beforeCreate() method
Maybe this changed in v3, but now you'd need $this->data.
5 replies
FFilament
Created by Xiaohou on 10/14/2024 in #❓┊help
How to refer to filament semantic color in blade file?
I was looking for this too, and came to the same conclusion. I borrowed some code from vendor/filament/forms/resources/views/components/field-wrapper/hint.blade.php and added this:
// resources/views/components/colored-content.blade.php
<span
class="fi-color-custom text-custom-600 dark:text-custom-400"
@style([
\Filament\Support\get_color_css_variables(
$color,
shades: [400, 600],
),
])
>
{{ $content }}
</span>
// resources/views/components/colored-content.blade.php
<span
class="fi-color-custom text-custom-600 dark:text-custom-400"
@style([
\Filament\Support\get_color_css_variables(
$color,
shades: [400, 600],
),
])
>
{{ $content }}
</span>
// Inside some Filament resource method
return new HtmlString('Add some '
. view('components.colored-content', [
'color' => 'danger',
'content' => 'CoLoR!'
])->render());
// Inside some Filament resource method
return new HtmlString('Add some '
. view('components.colored-content', [
'color' => 'danger',
'content' => 'CoLoR!'
])->render());
8 replies
FFilament
Created by Maxxx22 on 10/27/2023 in #❓┊help
Repeater: show delete button on each line conditionally
I'd really like this too. I'm considering a toggle component inside the repeater schema that marks the item for deletion when saving, but that's also not optimal.
3 replies
FFilament
Created by PabloZagni on 8/4/2024 in #❓┊help
Persist sort order
Maybe this functionality was added later? But this is plain Filament:
// Resource class
public static function table(Table $table): Table
{
return $table
->persistFiltersInSession()
->persistSortInSession()
->persistSearchInSession()
// ...
}
// Resource class
public static function table(Table $table): Table
{
return $table
->persistFiltersInSession()
->persistSortInSession()
->persistSearchInSession()
// ...
}
64 replies
FFilament
Created by Benjamin on 10/11/2023 in #❓┊help
Can't edit a resource if viewAny() is false (Model Policy)
I had a similar case, and ended up with viewAny: true and a global scope on the model to limit access.
6 replies
FFilament
Created by Cow on 11/27/2023 in #❓┊help
`FilamentColor::register()` having no effect (icons are same color as text)
Please note that you can also override the colors per panel using:
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->colors([
'primary' => Color::Amber,
//...
]);
}
}
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->colors([
'primary' => Color::Amber,
//...
]);
}
}
That was causing the register primary color change "not to work" at my end.
8 replies
FFilament
Created by John on 10/3/2023 in #❓┊help
Custom field with multiple checkboxes
Eventually I found out that I can use @foreach ($getChildComponents() ...
@foreach ($getChildComponentContainer()->getComponents() as ...)
@foreach ($getChildComponentContainer()->getComponents() as ...)
in the custom layout component blade, instead of {{ $getChildComponentContainer() }}. Now I can apply my custom layout/styling "inside"/"between" the default or custom components provided by ->schema([...]), instead of only "around" the fully rendered set of child components.
22 replies
FFilament
Created by John on 4/10/2024 in #❓┊help
Moving route registration removes theme css styling
Is there something magic about getPages() that makes custom styling work? I'm still stumped...
9 replies
FFilament
Created by John on 4/10/2024 in #❓┊help
Moving route registration removes theme css styling
Any clue?
9 replies
FFilament
Created by John on 4/10/2024 in #❓┊help
Moving route registration removes theme css styling
I've restarted npm run dev and run artisan optimize:clear
9 replies
FFilament
Created by John on 4/10/2024 in #❓┊help
Moving route registration removes theme css styling
After some more investigation: Every request hits Filament::registerViteTheme() in service provider. Also the broken theme request. But; the broken page only loads /filament/assets/app.css?id=ceb9a486dfc44ebe8adaa3bd510821e8 in network tab. While all other pages load http://[::1]:5173/resources/css/filament.css (and a bunch of custom stuff I put in the service provider).
9 replies
FFilament
Created by John on 4/10/2024 in #❓┊help
Moving route registration removes theme css styling
So next step is tenantConfig()->registerRoutes() which is a helper to get current tenant. But even directly in web.php fails.
9 replies
FFilament
Created by John on 4/10/2024 in #❓┊help
Moving route registration removes theme css styling
Ultimately I want to register routes depending on the current tenant.
9 replies
FFilament
Created by egmose5492dk on 4/10/2024 in #❓┊help
Only access to certain resulsts in resource - How do i limit that?
->contains('marina_id', $marina->id) looks suspicious
3 replies
FFilament
Created by John on 1/16/2024 in #❓┊help
Using form schema for PDF export
This approach saves me SO much time vs manually building and keeping track of a PDF html next to the Filament definition.
11 replies
FFilament
Created by John on 1/16/2024 in #❓┊help
Using form schema for PDF export
Oh, and you'll need something like this to generate the HTML. It has some stuff specific for my multi-form workflow, which you should change obviously:
<?php

namespace App\Http\Livewire;

use App\Models\BaseRequest;
use App\Models\Request;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Livewire\Component;
use Str;

class RequestPdf extends Component implements HasForms
{
use InteractsWithForms;

public function getHtml(BaseRequest|Request $request): string
{
$GLOBALS['pdf'] = true;

$html = '';

$first = true;
foreach (requestConfig(get_class($request))->getSteps($request) as $key => $form) {
$requestClass = Str::kebab(class_basename($request));
$title = $form->getTitle() ?: __("{$requestClass}.step.{$key}.title");
$html .= '<h1' . ($first ? '' : ' class="page-break"') . '>' . $title . '</h1>';
$html .= $this->makeForm()
->schema($form->getSchema())
->model($request)
->fill($request->toArray())
->render();
$first = false;
}

return $html;
}
}
<?php

namespace App\Http\Livewire;

use App\Models\BaseRequest;
use App\Models\Request;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Livewire\Component;
use Str;

class RequestPdf extends Component implements HasForms
{
use InteractsWithForms;

public function getHtml(BaseRequest|Request $request): string
{
$GLOBALS['pdf'] = true;

$html = '';

$first = true;
foreach (requestConfig(get_class($request))->getSteps($request) as $key => $form) {
$requestClass = Str::kebab(class_basename($request));
$title = $form->getTitle() ?: __("{$requestClass}.step.{$key}.title");
$html .= '<h1' . ($first ? '' : ' class="page-break"') . '>' . $title . '</h1>';
$html .= $this->makeForm()
->schema($form->getSchema())
->model($request)
->fill($request->toArray())
->render();
$first = false;
}

return $html;
}
}
11 replies
FFilament
Created by John on 1/16/2024 in #❓┊help
Using form schema for PDF export
Let me know if you need more explanation.
11 replies
FFilament
Created by John on 1/16/2024 in #❓┊help
Using form schema for PDF export
textarea.blade.php:
<div class="component textarea">
<div class="label">{{ $getLabel() }}</div>
<div class="value">
{!! nl2br(e($getState() ?? '-')) !!}
</div>
</div>
<div class="component textarea">
<div class="label">{{ $getLabel() }}</div>
<div class="value">
{!! nl2br(e($getState() ?? '-')) !!}
</div>
</div>
checkbox.blade.php:
<div class="component">
<div class="value">
<div class="symbol-and-text">
@if ($getState())
<div class="symbol">&#xf1fe;</div>
@else
<div class="symbol">&#xe835;</div>
@endif
{{ $getLabel() }}
</div>
</div>
</div>
<div class="component">
<div class="value">
<div class="symbol-and-text">
@if ($getState())
<div class="symbol">&#xf1fe;</div>
@else
<div class="symbol">&#xe835;</div>
@endif
{{ $getLabel() }}
</div>
</div>
</div>
(I use this css for checkbox:)
.form .symbol {
font-family: MaterialSymbolsOutlined, sans-serif;
font-size: 1.1rem;
}
.form .symbol {
font-family: MaterialSymbolsOutlined, sans-serif;
font-size: 1.1rem;
}
11 replies
FFilament
Created by John on 1/16/2024 in #❓┊help
Using form schema for PDF export
Sure. In composer.json, override ViewComponent.php:
"autoload": {
"exclude-from-classmap": [
"Filament\\Support\\Components\\ViewComponent"
],
"files": [
"app/Classes/Filament/Support/Components/ViewComponent.php"
]
},
"autoload": {
"exclude-from-classmap": [
"Filament\\Support\\Components\\ViewComponent"
],
"files": [
"app/Classes/Filament/Support/Components/ViewComponent.php"
]
},
Copy the vendor ViewComponent.php to your custom location. And change this part:
public function getView(): string
{
if (! isset($this->view)) {
throw new Exception('Class [' . static::class . '] extends [' . ViewComponent::class . '] but does not have a [$view] property defined.');
}

/**
* <CUSTOM>
*/
if (isset($GLOBALS['pdf'])) {
return strtr(
$this->view,
[
'forms::' => 'forms.pdf.',
'forms.components' => 'forms.pdf.components'
]
);
}
/**
* </CUSTOM>
*/

return $this->view;
}
public function getView(): string
{
if (! isset($this->view)) {
throw new Exception('Class [' . static::class . '] extends [' . ViewComponent::class . '] but does not have a [$view] property defined.');
}

/**
* <CUSTOM>
*/
if (isset($GLOBALS['pdf'])) {
return strtr(
$this->view,
[
'forms::' => 'forms.pdf.',
'forms.components' => 'forms.pdf.components'
]
);
}
/**
* </CUSTOM>
*/

return $this->view;
}
Then provide a custom blade for every component you use. E.g. fieldset.blade.php:
<fieldset class="component">
@if (filled($label = $getLabel()))
<legend>
{{ $label }}
</legend>
@endif

{{ $getChildComponentContainer() }}
</fieldset>
<fieldset class="component">
@if (filled($label = $getLabel()))
<legend>
{{ $label }}
</legend>
@endif

{{ $getChildComponentContainer() }}
</fieldset>
text-input.blade.php:
<div class="component">
<div class="label">{{ $getLabel() }}</div>
<div class="value">
@if ($getType() == 'date')
{{ $getState() ? \Carbon\Carbon::parse($getState())->isoFormat('D MMMM YYYY') : '-' }}
@else
{{ $getState() ?: '-' }}
@endif
</div>
</div>
<div class="component">
<div class="label">{{ $getLabel() }}</div>
<div class="value">
@if ($getType() == 'date')
{{ $getState() ? \Carbon\Carbon::parse($getState())->isoFormat('D MMMM YYYY') : '-' }}
@else
{{ $getState() ?: '-' }}
@endif
</div>
</div>
11 replies
FFilament
Created by John on 2/29/2024 in #❓┊help
Why are disabled() fields validated? (e.g. required())
It indeed does add browser validation using the required attribute, but browser validation is skipped when the component is also disabled. It's server validation that's skill kicking in, including a translated Fieldname X is required error message. The only difference between required() and rules('required') is that the latter doesn't give me the asterisk*. It still validates disabled fields. I couldn't get requiredIf() to work. But you lead me to another solution:
Toggle::make('return')->label('Return to previous step')
// ...
SomeField::make(..)->required(fn($get) => !$get('return'))
Toggle::make('return')->label('Return to previous step')
// ...
SomeField::make(..)->required(fn($get) => !$get('return'))
It's not very pretty to include that closure to every required field, but it's working. The whole form stays visible and editable, just the required validation is dropped when sending back.
4 replies