Skip to content

Instantly share code, notes, and snippets.

@joaopaulolndev
Created November 29, 2023 14:23
Show Gist options
  • Select an option

  • Save joaopaulolndev/23d031ec3844e6a0219f4e80cfc0be2c to your computer and use it in GitHub Desktop.

Select an option

Save joaopaulolndev/23d031ec3844e6a0219f4e80cfc0be2c to your computer and use it in GitHub Desktop.
UpdateLeadStatusAction
<?php
namespace App\Filament\Resources\LeadResource\Actions;
use App\Enums\LeadStatusEnum;
use App\Models\Lead;
use App\Models\LeadStatus;
use App\Services\UpdateLeadStatusService;
use App\Traits\HiddenLeadActionsTrait;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Notifications\Notification;
use Filament\Actions\Action as FormAction;
use Filament\Tables\Actions\Action as TableAction;
class UpdateLeadStatusAction
{
use HiddenLeadActionsTrait;
public static function handle(FormAction | TableAction $action): FormAction | TableAction
{
return $action->make(__('update_lead_status'))
->label(__('Update Status Lead'))
->icon('heroicon-o-arrow-path')
->requiresConfirmation()
->form(self::schema())
->action(self::onUpdate())
->hidden(self::hiddenRules());
}
public static function schema(): array
{
return [
Select::make('lead_status_id')
->label(__('Status'))
->native(false)
->options(LeadStatus::where('id', '<>', LeadStatusEnum::Converted())->pluck('name', 'id')->toArray())
->required(),
RichEditor::make('notes')
->label(__('Notes'))
->maxLength(65535)
->disableToolbarButtons([
'attachFiles',
])
];
}
public static function onUpdate(): \Closure
{
return static function(Lead $record, array $data) {
UpdateLeadStatusService::handle($record, $data['lead_status_id'], $data['notes']);
Notification::make()
->title(__('Saved successfully'))
->success()
->send();
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment