Marco Mapelli
Marco Mapelli
Explore posts from servers
FFilament
Created by Marco Mapelli on 9/14/2024 in #❓┊help
Refresh TableRepeater
In a resource, I have a TableRepeater. I want to add an item from a modal, but when I close the modal window, the TableRepeater doesn't refresh.
TableRepeater::make('sedi')
->relationship()
->columns(6)
->live()
->addActionLabel('Aggiungi Sede')

->headers([
Header::make('Nominativo'),
])
->renderHeader(false)
->schema([
Hidden::make('id')
->columnSpan(2),
Hidden::make('ragso1_nome'),
// ->columnSpan(4),
Placeholder::make('codice_ragso1_nome')
->hiddenLabel()
->content(function ($record): string {
return $record?->id.' - '.$record?->ragso1_nome;
}),
])
->addAction(function (Action $action) {
return $action
->form([
Select::make('nominativo')
->preload()
->live()
->options(function (Nominativo $record) {
// dd($record->id);
return Nominativo::whereNull('nominativo_principale_id')
->where('id', '<>', $record->id)
->orderBy('ragso1_nome')
->get()
->mapWithKeys(function ($item) {
return [$item->id => $item->id . ' - ' . $item->ragso1_nome];
});
})
->searchable(),
])
->after(function ($livewire, TableRepeater $component) {
$state = $component->getState();
unset($state[array_key_last($state)]);
})
->before(function (array $data, array $arguments, TableRepeater $component, Nominativo $record_master, $livewire) {
$id_principale = (int) $data['nominativo'];
$nominativo = Nominativo::find($id_principale);
$nominativo->nominativo_principale_id = $record_master->id;
$nominativo->save();
$state = $component->getState();
TableRepeater::make('sedi')
->relationship()
->columns(6)
->live()
->addActionLabel('Aggiungi Sede')

->headers([
Header::make('Nominativo'),
])
->renderHeader(false)
->schema([
Hidden::make('id')
->columnSpan(2),
Hidden::make('ragso1_nome'),
// ->columnSpan(4),
Placeholder::make('codice_ragso1_nome')
->hiddenLabel()
->content(function ($record): string {
return $record?->id.' - '.$record?->ragso1_nome;
}),
])
->addAction(function (Action $action) {
return $action
->form([
Select::make('nominativo')
->preload()
->live()
->options(function (Nominativo $record) {
// dd($record->id);
return Nominativo::whereNull('nominativo_principale_id')
->where('id', '<>', $record->id)
->orderBy('ragso1_nome')
->get()
->mapWithKeys(function ($item) {
return [$item->id => $item->id . ' - ' . $item->ragso1_nome];
});
})
->searchable(),
])
->after(function ($livewire, TableRepeater $component) {
$state = $component->getState();
unset($state[array_key_last($state)]);
})
->before(function (array $data, array $arguments, TableRepeater $component, Nominativo $record_master, $livewire) {
$id_principale = (int) $data['nominativo'];
$nominativo = Nominativo::find($id_principale);
$nominativo->nominativo_principale_id = $record_master->id;
$nominativo->save();
$state = $component->getState();
2 replies
FFilament
Created by Marco Mapelli on 6/10/2024 in #❓┊help
Pagination and modal with tabs
I have a custom page where I display a table with an image. When I click on the image, a modal opens with tabs inside. In the list resource, I created:
public function setPage($page, $pageName = 'page')
{
parent::setPage($page, $pageName);
$this->dispatch('scroll-to-top');
}
public function setPage($page, $pageName = 'page')
{
parent::setPage($page, $pageName);
$this->dispatch('scroll-to-top');
}
The problem is that clicking on the tabs is interpreted as pagination, so the $this->dispatch('scroll-to-top'); is executed. How can I fix this?
3 replies
FFilament
Created by Marco Mapelli on 4/22/2024 in #❓┊help
Action in footer table
Hello, is it possible to insert an action in the footer of the table (getFooterActions ??)? I need to create a button that, once I have finished scrolling through the entire table, can redirect me to another page. Now i have this in List.. resource:
protected function getHeaderActions(): array
{
return [
Action::make('showroom')
->label(__('b2brstoys.showroom.torna_a_showroom'))
->color('success')
// ->action(function () {
// return redirect(ShowroomResource::getUrl('index'));
// }),
->url(fn (): string => ShowroommarcheResource::getUrl()),
];
}
protected function getHeaderActions(): array
{
return [
Action::make('showroom')
->label(__('b2brstoys.showroom.torna_a_showroom'))
->color('success')
// ->action(function () {
// return redirect(ShowroomResource::getUrl('index'));
// }),
->url(fn (): string => ShowroommarcheResource::getUrl()),
];
}
3 replies
FFilament
Created by Marco Mapelli on 4/5/2024 in #❓┊help
HELP getGlobalSearchResults
No description
7 replies
FFilament
Created by Marco Mapelli on 2/6/2024 in #❓┊help
Enum color in DB
What is the best way to save the colors of an enum in the db, so that the administrator can change the color?
...
public function getColor(): string|array|null
{
return match ($this) {
self::Ordinato => Color::Cyan,
self::Eseguito => Color::Blue,
self::Verificato => Color::Yellow,
};
}
...
public function getColor(): string|array|null
{
return match ($this) {
self::Ordinato => Color::Cyan,
self::Eseguito => Color::Blue,
self::Verificato => Color::Yellow,
};
}
class Color extends Model
{
protected $table = 'colors';
protected $fillable = ['name', 'value'];
}
...
public function getColor(): string|array|null
{
return match ($this) {
self::Ordinato => Color::where('name', self::Ordinato)->first()->value,
self::Eseguito => Color::where('name', self::Eseguito)->first()->value,
self::Verificato => Color::where('name', self::Verificato)->first()->value,
};
}
class Color extends Model
{
protected $table = 'colors';
protected $fillable = ['name', 'value'];
}
...
public function getColor(): string|array|null
{
return match ($this) {
self::Ordinato => Color::where('name', self::Ordinato)->first()->value,
self::Eseguito => Color::where('name', self::Eseguito)->first()->value,
self::Verificato => Color::where('name', self::Verificato)->first()->value,
};
}
6 replies
FFilament
Created by Marco Mapelli on 12/13/2023 in #❓┊help
TextInput numeric with step
I have the following code:
TextInput::make('qta')
->numeric()
->step(96)
TextInput::make('qta')
->numeric()
->step(96)
Why do I only validate multiples of 96? I i insert 24 message: the value... from 0 to 96
3 replies
FFilament
Created by Marco Mapelli on 12/4/2023 in #❓┊help
Active Tab in modal
I’m creating a new component. I have to display an image and clicking on it I have to open a modal window with a tab to create a gallery. I can’t get tab1 to open by default
...<x-filament::tabs>
<x-filament::tabs.item alpine-active="$wire.activeTab == '1'"
wire:click="$set('activeTab', '1')">
1
</x-filament::tabs.item>
@php
$conta = 2;
@endphp
@foreach ($getRecord()->articoli->foto as $image)
@if ($image->is_default == false)
<x-filament::tabs.item alpine-active="$wire.activeTab == '{{ $conta }}'"
wire:click="$set('activeTab', '{{ $conta }}')">
{{ $conta }}
</x-filament::tabs.item>
@php
$conta = $conta + 1;
@endphp
@endif
@endforeach
</x-filament::tabs>
<div x-show="$wire.activeTab == '1'">
<img id="{{ $getRecord()->articoli->foto[0]->filename }}"
src="{{ asset(Storage::url('article_images/' . $getRecord()->articoli->codart . '/' . $getRecord()->articoli->foto[0]->filename)) }}"
alt="{{ $getRecord()->articoli->foto[0]->filename }}">
</div>
@php
$conta = 2;
@endphp
@foreach ($getRecord()->articoli->foto as $image)
@if ($image->is_default == false)
<div x-show="$wire.activeTab == '{{ $conta }}' ">
<img id="{{ $image->filename }}"
src="{{ asset(Storage::url('article_images/' . $getRecord()->articoli->codart . '/' . $image->filename)) }}"
alt="{{ $image->filename }}">
</div>
@php
$conta = $conta + 1;
@endphp
@endif
@endforeach
</x-filament::modal>
...<x-filament::tabs>
<x-filament::tabs.item alpine-active="$wire.activeTab == '1'"
wire:click="$set('activeTab', '1')">
1
</x-filament::tabs.item>
@php
$conta = 2;
@endphp
@foreach ($getRecord()->articoli->foto as $image)
@if ($image->is_default == false)
<x-filament::tabs.item alpine-active="$wire.activeTab == '{{ $conta }}'"
wire:click="$set('activeTab', '{{ $conta }}')">
{{ $conta }}
</x-filament::tabs.item>
@php
$conta = $conta + 1;
@endphp
@endif
@endforeach
</x-filament::tabs>
<div x-show="$wire.activeTab == '1'">
<img id="{{ $getRecord()->articoli->foto[0]->filename }}"
src="{{ asset(Storage::url('article_images/' . $getRecord()->articoli->codart . '/' . $getRecord()->articoli->foto[0]->filename)) }}"
alt="{{ $getRecord()->articoli->foto[0]->filename }}">
</div>
@php
$conta = 2;
@endphp
@foreach ($getRecord()->articoli->foto as $image)
@if ($image->is_default == false)
<div x-show="$wire.activeTab == '{{ $conta }}' ">
<img id="{{ $image->filename }}"
src="{{ asset(Storage::url('article_images/' . $getRecord()->articoli->codart . '/' . $image->filename)) }}"
alt="{{ $image->filename }}">
</div>
@php
$conta = $conta + 1;
@endphp
@endif
@endforeach
</x-filament::modal>
3 replies
FFilament
Created by Marco Mapelli on 11/16/2023 in #❓┊help
Resize section aside heading and description
No description
7 replies
FFilament
Created by Marco Mapelli on 11/15/2023 in #❓┊help
disable field dynamically but save it in db
Hi, I need to dynamically disable a Togglebut I have to save the field: how come it doesn’t work ?
...
switch ($tipo) {
case SoggettoTipo::Contraente:
$is_contraente = true;
$is_contraente_disabled = true;
break;
case SoggettoTipo::DlDecRup:
$is_dldecrup = true;
$is_dldecrup_disabled = true;
break;
}
...
Toggle::make('is_contraente')
->default($is_contraente)
->dehydrated()
->disabled($is_contraente_disabled),
...
switch ($tipo) {
case SoggettoTipo::Contraente:
$is_contraente = true;
$is_contraente_disabled = true;
break;
case SoggettoTipo::DlDecRup:
$is_dldecrup = true;
$is_dldecrup_disabled = true;
break;
}
...
Toggle::make('is_contraente')
->default($is_contraente)
->dehydrated()
->disabled($is_contraente_disabled),
7 replies
FFilament
Created by Marco Mapelli on 10/25/2023 in #❓┊help
Image in split table
No description
2 replies
FFilament
Created by Marco Mapelli on 9/20/2023 in #❓┊help
Logo in login page and after logged in
Hello, I’m configuring the logo, but when I’m on the login page is very small, when I’m logged in is right. How do I enlarge the logo on the login page? Can I have two different logos between the login page and after I’m logged in?
7 replies
FFilament
Created by Marco Mapelli on 9/15/2023 in #❓┊help
Customize Record Title
Hi, in ContractResource i have:
protected static ?string $recordTitleAttribute = 'id';
protected static ?string $recordTitleAttribute = 'id';
How can I customize the title so that I can see "View Contract No. [id]" or "Edit Contract No. [4]" ?
12 replies
FFilament
Created by Marco Mapelli on 7/27/2023 in #❓┊help
execute function in resource from edit
Hi, in PfcResource.php i have a static function:
public static function CalcoliQta(\Closure $get, callable $set, $livewire, $context = '')
{...
public static function CalcoliQta(\Closure $get, callable $set, $livewire, $context = '')
{...
I want to execute it when the record is in edit mode: how??
4 replies