Trait isnt recognized
So I created my own Trait, and it seems like it isnt recognized by the blade file:
I added the trait to the Section php file:
<?php
namespace Filament\Support\Concerns;
use Closure;
use Illuminate\Contracts\Support\Htmlable;
trait HasDuration
{
protected string|float|Closure|null $duration = null;
public function duration(string|Htmlable|float|Closure|null $duration = null): static
{
$this->duration = $duration;
return $this;
}
public function getDuration(): float|null|Htmlable
{
dd($this->duration);
return $this->evaluate($this->duration);
}
}
<?php
namespace Filament\Support\Concerns;
use Closure;
use Illuminate\Contracts\Support\Htmlable;
trait HasDuration
{
protected string|float|Closure|null $duration = null;
public function duration(string|Htmlable|float|Closure|null $duration = null): static
{
$this->duration = $duration;
return $this;
}
public function getDuration(): float|null|Htmlable
{
dd($this->duration);
return $this->evaluate($this->duration);
}
}
<?php
namespace Filament\Forms\Components;
// ...
use Filament\Support\Concerns\HasDuration;
// ...
class Section extends Component implements Contracts\CanConcealComponents, Contracts\CanEntangleWithSingularRelationships
{
use Concerns\CanBeCollapsed;
use Concerns\CanBeCompacted;
use Concerns\EntanglesStateWithSingularRelationship;
use HasDescription;
use HasDuration;
use HasExtraAlpineAttributes;
use HasHeading;
use HasIcon;
use HasIconColor;
// ...
}
<?php
namespace Filament\Forms\Components;
// ...
use Filament\Support\Concerns\HasDuration;
// ...
class Section extends Component implements Contracts\CanConcealComponents, Contracts\CanEntangleWithSingularRelationships
{
use Concerns\CanBeCollapsed;
use Concerns\CanBeCompacted;
use Concerns\EntanglesStateWithSingularRelationship;
use HasDescription;
use HasDuration;
use HasExtraAlpineAttributes;
use HasHeading;
use HasIcon;
use HasIconColor;
// ...
}
2 Replies
section.blade.php
every time I dd($duration) it shows null. Any idea why?
In the form of my resource, I have a Section component, and I added ->duration(12.1). The blade file should show 12.1 but it always shows null.
Even added this:
Works now!
Turned out this belonged to the infolists lol
@php
use Filament\Support\Enums\IconSize;
@endphp
@props([
'aside' => false,
'collapsed' => false,
'collapsible' => false,
'compact' => false,
'contentBefore' => false,
'description' => null,
'headerEnd' => null,
'heading' => null,
'icon' => null,
'iconColor' => 'gray',
'iconSize' => IconSize::Large,
'duration' => null,
])
@php
$hasDescription = filled((string) $description);
$hasHeading = filled($heading);
$hasIcon = filled($icon);
$hasDuration = filled((float) $duration);
$hasHeader = $hasIcon || $hasHeading || $hasDescription || $collapsible || filled((string) $headerEnd) || $hasDuration;
dd($duration)
@endphp
@php
use Filament\Support\Enums\IconSize;
@endphp
@props([
'aside' => false,
'collapsed' => false,
'collapsible' => false,
'compact' => false,
'contentBefore' => false,
'description' => null,
'headerEnd' => null,
'heading' => null,
'icon' => null,
'iconColor' => 'gray',
'iconSize' => IconSize::Large,
'duration' => null,
])
@php
$hasDescription = filled((string) $description);
$hasHeading = filled($heading);
$hasIcon = filled($icon);
$hasDuration = filled((float) $duration);
$hasHeader = $hasIcon || $hasHeading || $hasDescription || $collapsible || filled((string) $headerEnd) || $hasDuration;
dd($duration)
@endphp
Section::make()
->description('Create users')
->icon('heroicon-s-user-plus')
->collapsible()
->duration(12.1)
])
Section::make()
->description('Create users')
->icon('heroicon-s-user-plus')
->collapsible()
->duration(12.1)
])
<x-filament::section
:aside="$isAside"
:collapsed="$isCollapsed()"
:collapsible="$isCollapsible() && (! $isAside)"
:compact="$isCompact()"
:duration="$getDuration()" <------------------------
:content-before="$isContentBefore()"
:description="$getDescription()"
:heading="$getHeading()"
:icon="$getIcon()"
:icon-color="$getIconColor()"
:icon-size="$getIconSize()"
:attributes="
\Filament\Support\prepare_inherited_attributes($attributes)
->merge([
'id' => $getId(),
], escape: false)
->merge($getExtraAttributes(), escape: false)
->merge($getExtraAlpineAttributes(), escape: false)
"
>
{{ $getChildComponentContainer() }}
</x-filament::section>
<x-filament::section
:aside="$isAside"
:collapsed="$isCollapsed()"
:collapsible="$isCollapsible() && (! $isAside)"
:compact="$isCompact()"
:duration="$getDuration()" <------------------------
:content-before="$isContentBefore()"
:description="$getDescription()"
:heading="$getHeading()"
:icon="$getIcon()"
:icon-color="$getIconColor()"
:icon-size="$getIconSize()"
:attributes="
\Filament\Support\prepare_inherited_attributes($attributes)
->merge([
'id' => $getId(),
], escape: false)
->merge($getExtraAttributes(), escape: false)
->merge($getExtraAlpineAttributes(), escape: false)
"
>
{{ $getChildComponentContainer() }}
</x-filament::section>
Solution
Make sure you add
:duration="$getDuration()" to the proper file