F
Filament6mo ago
Flo

Modal does not work in a Custom Page

Hello, I am building a custom page but nothing happens when I click on the column action :
/* @method Server getRecord() */
class SoftwareServer extends Page implements HasActions, HasTable
{
use InteractsWithRecord, InteractsWithTable;

protected static string $resource = ServerResource::class;

public function mount(int|string $record): void
{
$this->record = $this->resolveRecord($record);

static::authorizeResourceAccess();
}

public function table(Table $table): Table
{
return $table
->query(Software::queryForSoftwares($this->getRecord()))
->columns([
TextColumn::make('name'),
])
->actions([
Tables\Actions\Action::make('test')
->label('Test')
->form([
TextInput::make('name'),
])
->action(fn (array $data) => dd($data)),
])
->paginated(false);
}
}
/* @method Server getRecord() */
class SoftwareServer extends Page implements HasActions, HasTable
{
use InteractsWithRecord, InteractsWithTable;

protected static string $resource = ServerResource::class;

public function mount(int|string $record): void
{
$this->record = $this->resolveRecord($record);

static::authorizeResourceAccess();
}

public function table(Table $table): Table
{
return $table
->query(Software::queryForSoftwares($this->getRecord()))
->columns([
TextColumn::make('name'),
])
->actions([
Tables\Actions\Action::make('test')
->label('Test')
->form([
TextInput::make('name'),
])
->action(fn (array $data) => dd($data)),
])
->paginated(false);
}
}
And the associated view:
<x-filament-panels::page>
{{ $this->table }}

<x-filament-actions::modals/>
</x-filament-panels::page>
<x-filament-panels::page>
{{ $this->table }}

<x-filament-actions::modals/>
</x-filament-panels::page>
Why ? In the browser console, an ajax call to the /livewire/update route appears correctly
11 Replies
Robbyn R
Robbyn R6mo ago
try
->form(fn($form) => $form->schema([
TextInput::make('name'),
]))
->form(fn($form) => $form->schema([
TextInput::make('name'),
]))
Flo
Flo6mo ago
not working I also tried the following code without success:
public function table(Table $table): Table
{
return $table
->query(Software::queryForSoftwares($this->getRecord()))
->columns([
TextColumn::make('name'),
])
->actions([
Action::make('test')
->modalContent(fn (Software $software): View => view('livewire.view-file'))
->action(fn () => dd('test')),
])
->paginated(false);
}
public function table(Table $table): Table
{
return $table
->query(Software::queryForSoftwares($this->getRecord()))
->columns([
TextColumn::make('name'),
])
->actions([
Action::make('test')
->modalContent(fn (Software $software): View => view('livewire.view-file'))
->action(fn () => dd('test')),
])
->paginated(false);
}
Pritbor
Pritbor6mo ago
You dont need <x-filament-actions::modals/>
Flo
Flo6mo ago
Even deleting it doesn't work
Pritbor
Pritbor6mo ago
Here is my code. Just delete action model code from view. Your action should automatically trigger model or if you specify sliderOver() like me it will create slideOver.
Pritbor
Pritbor6mo ago
Further please inspect if you are passing data correctly. did you debug the code and see if you enter action code. do you get list of records with name entry and test button.
Flo
Flo6mo ago
Flo
Flo6mo ago
My actually code :
class SoftwareServer extends Page implements HasTable
{
use InteractsWithRecord, InteractsWithTable;

protected static string $resource = ServerResource::class;

protected static string $view = 'filament.resources.server-resource.pages.software-server';

protected static ?string $title = 'Softwares';

protected static ?string $navigationIcon = 'heroicon-s-code-bracket';

public function mount(int|string $record): void
{
$this->record = $this->resolveRecord($record);

static::authorizeResourceAccess();
}

public function table(Table $table): Table
{
return $table
->query(Software::queryForSoftwares($this->getRecord()))
->columns([
TextColumn::make('name'),
])
->actions([
Action::make('test')
->modalContent(fn (Software $software): View => view('livewire.view-file'))
->action(fn () => dd('test')),
])
->paginated(false);
}
}
class SoftwareServer extends Page implements HasTable
{
use InteractsWithRecord, InteractsWithTable;

protected static string $resource = ServerResource::class;

protected static string $view = 'filament.resources.server-resource.pages.software-server';

protected static ?string $title = 'Softwares';

protected static ?string $navigationIcon = 'heroicon-s-code-bracket';

public function mount(int|string $record): void
{
$this->record = $this->resolveRecord($record);

static::authorizeResourceAccess();
}

public function table(Table $table): Table
{
return $table
->query(Software::queryForSoftwares($this->getRecord()))
->columns([
TextColumn::make('name'),
])
->actions([
Action::make('test')
->modalContent(fn (Software $software): View => view('livewire.view-file'))
->action(fn () => dd('test')),
])
->paginated(false);
}
}
For information, Software is a model using sushi:
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;

class Software extends Model
{
use Sushi;

protected static array $softwares = [];

public static function queryForSoftwares(Server $server): Builder
{
static::$softwares = $server->installedSoftware()->toArray();

return static::query();
}

public function getRows(): array
{
return collect(static::$softwares)->map(function ($software) {
return [
'id' => $software->value,
'name' => $software->getDisplayName(),
'hasRestartTask' => (bool) $software->restartTaskClass(),
'hasUpdateAlternativesTask' => (bool) $software->updateAlternativesTask(),
];
})->toArray();
}
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;

class Software extends Model
{
use Sushi;

protected static array $softwares = [];

public static function queryForSoftwares(Server $server): Builder
{
static::$softwares = $server->installedSoftware()->toArray();

return static::query();
}

public function getRows(): array
{
return collect(static::$softwares)->map(function ($software) {
return [
'id' => $software->value,
'name' => $software->getDisplayName(),
'hasRestartTask' => (bool) $software->restartTaskClass(),
'hasUpdateAlternativesTask' => (bool) $software->updateAlternativesTask(),
];
})->toArray();
}
}
Pritbor
Pritbor6mo ago
can you add like
->action(fn () => dd('test'))->slideOver(),
->action(fn () => dd('test'))->slideOver(),
and check. remove ->modalContent(fn (Software $software): View => view('livewire.view-file')) rather create simple form like your shared. It should trigger form in slideover. Dont use any modal in view.
public function table(Table $table): Table
{
return $table
->query(Software::queryForSoftwares($this->getRecord()))
->columns([
TextColumn::make('name'),
])
->actions([
Tables\Actions\Action::make('test')
->label('Test')
->form([
TextInput::make('name'),
])
->action(fn (array $data) => dd($data))->slideOver(),
])
->paginated(false);
}
public function table(Table $table): Table
{
return $table
->query(Software::queryForSoftwares($this->getRecord()))
->columns([
TextColumn::make('name'),
])
->actions([
Tables\Actions\Action::make('test')
->label('Test')
->form([
TextInput::make('name'),
])
->action(fn (array $data) => dd($data))->slideOver(),
])
->paginated(false);
}
Flo
Flo6mo ago
I always have the same result. In the browser console, /livewire/update is called in post, but nothing is displayed (like in the video) @Dennis Koch sorry to ping you, but we can't find the reason for this problem... no error message is displayed. Am I doing something wrong? I don't know why but it works now... I didn't do anything in particular so I suspect the cache... it's frustrating not knowing the reason
public function table(Table $table): Table
{
return $table
->query(Software::queryForSoftwares($this->getRecord()))
->columns([
TextColumn::make('name'),
])
->actions([
Action::make('test')
->label('Test')
->form([
TextInput::make('name'),
])
->action(fn (array $data) => dd($data)),
])
->paginated(false);
}
public function table(Table $table): Table
{
return $table
->query(Software::queryForSoftwares($this->getRecord()))
->columns([
TextColumn::make('name'),
])
->actions([
Action::make('test')
->label('Test')
->form([
TextInput::make('name'),
])
->action(fn (array $data) => dd($data)),
])
->paginated(false);
}
Want results from more Discord servers?
Add your server
More Posts