F
Filament3mo ago
Neamix

Filament Page

Hey guys, I am still new to filament and i have a quick question after read the filament page documentation https://filamentphp.com/docs/2.x/admin/pages/actions i only find an explaination on how to use filament page functions but i didn't find how can i can view this functions as example
protected function getActions(): array
{
return [
Action::make('settings')->color('secondary'),
];
}
protected function getActions(): array
{
return [
Action::make('settings')->color('secondary'),
];
}
this function should as far as know display a button called settings but after i use it directly in filament class nothing appeared so i found that i need to call actions in blade but i cant find any docs on how to do that so anyone have any idea where i can find this infos
12 Replies
jigsaw
jigsaw3mo ago
are you checking wrong version? because you tagged with "v3" but the document URL is "v2"
Neamix
NeamixOP3mo ago
yea that was my mistake but still cant find how to add actions in a custom page
jigsaw
jigsaw3mo ago
which class are you using? is it a custom class or a resource?
Neamix
NeamixOP3mo ago
no custom class
<?php

namespace App\Filament\Pages;

use Filament\Pages\Page;
use Filament\Actions\Action;

class Members extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.members';
protected static ?string $navigationLabel = 'Members';
protected static ?string $title = 'Members';
protected ?string $heading = '';
public $showModal = "ddddd";


protected function getActions(): array
{
return [
Action::make('openModal')
->label('Open Modal')
->icon('heroicon-o-plus')
->color('primary')
->action('openModal') // Link to a method to handle opening the modal
];
}

public static function getNavigationLabel(): string
{
return static::$navigationLabel;
}

public function openModal()
{
$this->dispatch('open-modal', id: 'invite-user');
}

public function submitForm(array $data)
{
$this->notify('success', 'Member added successfully.');
}
}
<?php

namespace App\Filament\Pages;

use Filament\Pages\Page;
use Filament\Actions\Action;

class Members extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.members';
protected static ?string $navigationLabel = 'Members';
protected static ?string $title = 'Members';
protected ?string $heading = '';
public $showModal = "ddddd";


protected function getActions(): array
{
return [
Action::make('openModal')
->label('Open Modal')
->icon('heroicon-o-plus')
->color('primary')
->action('openModal') // Link to a method to handle opening the modal
];
}

public static function getNavigationLabel(): string
{
return static::$navigationLabel;
}

public function openModal()
{
$this->dispatch('open-modal', id: 'invite-user');
}

public function submitForm(array $data)
{
$this->notify('success', 'Member added successfully.');
}
}
Neamix
NeamixOP3mo ago
yes that's what i want thx @awcodes plz i have another question i edit the my logic so i can added action modal with a form like this
public function updateAuthor(): Action
{
return Action::make('updateAuthor')
->form([
Select::make('role')
->label('فئة المستخدم')
->options([
'1' => 'ادمن',
'2' => 'طبيب'
])
->required(),
TextInput::make('email')
->label('البريد الاليكتروني')
->afterStateUpdated(function (callable $set, $state) {
// Check if email exists in admin table
if (DB::table('admins')->where('email', $state)->exists()) {
// Set a validation error for the email input
$set('email', 'The email already exists.');
}
})
->unique()
])
->action(function (array $data): void {

})
->modalWidth(MaxWidth::Small);
}
public function updateAuthor(): Action
{
return Action::make('updateAuthor')
->form([
Select::make('role')
->label('فئة المستخدم')
->options([
'1' => 'ادمن',
'2' => 'طبيب'
])
->required(),
TextInput::make('email')
->label('البريد الاليكتروني')
->afterStateUpdated(function (callable $set, $state) {
// Check if email exists in admin table
if (DB::table('admins')->where('email', $state)->exists()) {
// Set a validation error for the email input
$set('email', 'The email already exists.');
}
})
->unique()
])
->action(function (array $data): void {

})
->modalWidth(MaxWidth::Small);
}
i want when the email not unique to display validation error under the input i added unique on email chain but it didnt appear
awcodes
awcodes3mo ago
You don’t need the adterStateUpdated() ->unique() will add the validation rules automatically.
Neamix
NeamixOP3mo ago
@awcodes yes thats true but i want to know how to display this message to user as right now when user enter an used email and click send invitation the modal close and nothing happend
awcodes
awcodes3mo ago
Are you doing anything in the action?
Neamix
NeamixOP3mo ago
@awcodes the user just enter the role and email and then send invitation so the only action is sending
Neamix
NeamixOP3mo ago
thx for support
Want results from more Discord servers?
Add your server