ifnex/04_Laravel/app/Filament/Pages/SettingsPage.php

80 lines
2.4 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Models\SystemSetting;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
class SettingsPage extends Page
{
use InteractsWithForms;
protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';
protected static string $view = 'filament.pages.settings-page';
// نام منو در سایدبار
protected static ?string $navigationLabel = 'تنظیمات ارز و سود';
// اینکه کجا تو منو نمایش داده بشه (ترتیب)
protected static ?int $navigationSort = 100;
public ?SystemSetting $record = null;
// وقتی صفحه باز میشه، رکورد تنظیمات رو می‌گیره
public function mount(): void
{
$this->record = SystemSetting::first();
}
// ساختار فرم
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('dirham_rate')
->label('نرخ درهم')
->numeric()
->required()
->prefix('ریال'),
TextInput::make('dollar_rate')
->label('نرخ دلار')
->numeric()
->prefix('ریال'),
TextInput::make('yuan_rate')
->label('نرخ یوان')
->numeric()
->prefix('ریال'),
TextInput::make('euro_rate')
->label('نرخ یورو')
->numeric()
->prefix('ریال'),
TextInput::make('profit_percent')
->label('ضریب سود شرکت')
->numeric()
->required()
->suffix('ضرب')
->default(1.25),
])
->statePath('record');
}
// دکمه ذخیره
public function save(): void
{
$this->record->save();
Notification::make()
->title('ذخیره شد')
->body('تنظیمات نرخ ارز با موفقیت آپدیت شدند.')
->success()
->send();
}
}