Tony
Tony
FFilament
Created by bearer on 2/14/2024 in #❓┊help
What parameters can I specify in disabled() closure of Action?
👀
5 replies
FFilament
Created by bearer on 2/14/2024 in #❓┊help
What parameters can I specify in disabled() closure of Action?
5 replies
FFilament
Created by Tony on 2/10/2024 in #❓┊help
Header action button not refreshing
👀
3 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
its a bit hard to explain
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
so they wont collide, or overwrite themselves
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
you can put both in the same resource because they are tweaked so they only sync the filters of its own type
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
its the same, just changing Tag for Town
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
i have another component like this for the other type of filters, TownSelect
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
TagSelect::make('tag')->label(Town)
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
so in the resource i just had to do:
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
I extracted the custom component to a class
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
@danielplomp
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
<?php

namespace App\Filament\Fields;

use App\Models\Filter;
use Filament\Forms\Components\Select;
use Illuminate\Database\Eloquent\Builder;

class TagSelect extends Select
{
public function setUp(): void
{
parent::setUp();

$this->multiple()
->searchable()
->relationship('filters', 'name', fn (Builder $query) => $query->tag())
->loadStateFromRelationshipsUsing(function (Select $component, $state): void {
if (filled($state)) {
return;
}

$relationship = $component->getRelationship();

$relatedModels = $relationship->where('type', 'tag')->getResults();
$component->state(
$relatedModels
->pluck($relationship->getRelatedKeyName())
->map(static fn ($key): string => strval($key))
->toArray(),
);
})
->saveRelationshipsUsing(function (Select $component, $state) {
$relationship = $component->getRelationship();

$allTagFilters = Filter::where('type', 'tag')->pluck('id');

$relationship->detach($allTagFilters);
$relationship->attach($state);
});
}
}
<?php

namespace App\Filament\Fields;

use App\Models\Filter;
use Filament\Forms\Components\Select;
use Illuminate\Database\Eloquent\Builder;

class TagSelect extends Select
{
public function setUp(): void
{
parent::setUp();

$this->multiple()
->searchable()
->relationship('filters', 'name', fn (Builder $query) => $query->tag())
->loadStateFromRelationshipsUsing(function (Select $component, $state): void {
if (filled($state)) {
return;
}

$relationship = $component->getRelationship();

$relatedModels = $relationship->where('type', 'tag')->getResults();
$component->state(
$relatedModels
->pluck($relationship->getRelatedKeyName())
->map(static fn ($key): string => strval($key))
->toArray(),
);
})
->saveRelationshipsUsing(function (Select $component, $state) {
$relationship = $component->getRelationship();

$allTagFilters = Filter::where('type', 'tag')->pluck('id');

$relationship->detach($allTagFilters);
$relationship->attach($state);
});
}
}
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
Yup i think so @danielplomp
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
Ill share the code sortly
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
Yes @danielplomp
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
thank you!
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
yeah @Dan Harrin probably ill try that too
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
its a local scope @josef it adds ->where('type', 'pathology') to the query
42 replies
FFilament
Created by Tony on 4/21/2023 in #❓┊help
Problem with two select fields using same relationship
yeah pretty weird
42 replies