F
Filament16mo ago
Matthew

Trait isnt recognized

So I created my own Trait, and it seems like it isnt recognized by the blade 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);
}
}
I added the trait to the Section php file:
<?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;
// ...
}
Solution:
Make sure you add :duration="$getDuration()" to the proper file...
Jump to solution
2 Replies
Matthew
MatthewOP16mo ago
section.blade.php
@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
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.
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)
])
Even added this:
<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>
Works now! Turned out this belonged to the infolists lol
Solution
Matthew
Matthew16mo ago
Make sure you add :duration="$getDuration()" to the proper file
Want results from more Discord servers?
Add your server