[Filament] 打造一個 Laravel Filament 站台
教學課程
☞ Filament PHP V3 Tutorial
☞ Filament 3 course for beginners
☞ 官方教程
☞ 測試資料
〈1〉建立一個 laravel filament 網站 登錄網址:
〈2〉生成 Filament 資源:php artisan make:filament-resource (1) 先建立
(2) 為 App\Models\Customer Model 建立資源,存放於
Pages 目錄下的類別用於自訂應用程式中和資源互動的頁面。這些頁面是全頁 Livewire 元件,你可以根據需要自訂。
CustomerResource.php
├── CustomerResource/
├──── Pages/
│ ├── CreateCustomer.php (新建頁,預設生成)
│ ├── EditCustomer.php (編輯頁,預設生成)
│ ├── ListCustomer.php (列表頁,預設生成)
│ └── ViewCustomers.php (檢視頁)
● form() 方法:為新建和編輯頁面建立表單
● table() 方法:定義資源列表頁
● getRelations() 方法:定義與當前資源相關聯的其他資源或模型的關聯
● getPages() 方法:指定資源的頁面路由
〈3〉Filament 資源設定值
〈4〉自定義頁面:php artisan make:filament-page SortUsers --resource=UserResource --type=custom ☞ NEW in Filament 3: Infolist Builder
☞ Create Custom Pages in Filament PHP - The Easy Way
☞ Filament Custom Page Example: Invoice Preview
☞ 3 | Add Custom Page in filament panel
☞ Filament: Eager Loading in Custom Column View
☞ Filament: Repeater "Live" Form Changes with afterStateUpdated()
☞ Filament 3 course for beginners
☞ 官方教程
☞ 測試資料
php artisan make:model Country -m php artisan make:model State -m php artisan make:model City -m php artisan make:model Department -m php artisan make:model Employee -m php artisan make:filament-resource Country php artisan make:filament-resource State --generate php artisan make:filament-resource City --generate --view php artisan make:filament-resource Department --generate --view php artisan make:filament-resource Employee --generate --view php artisan make:filament-resource User --generate --view
〈1〉建立一個 laravel filament 網站 登錄網址:
網域/admin
# 建立一個 Laravel 專案 composer create-project laravel/laravel [專案名稱] # 加入 filament composer require filament/filament:"^3.2" -W php artisan filament:install --panels # 創建用戶 php artisan make:filament-user # 建立站台需要的 model php artisan make:model -m php artisan migrate
〈2〉生成 Filament 資源:php artisan make:filament-resource (1) 先建立
App\Models\Customer
(2) 為 App\Models\Customer Model 建立資源,存放於
app/Filament/Resources
目錄下:Pages 目錄下的類別用於自訂應用程式中和資源互動的頁面。這些頁面是全頁 Livewire 元件,你可以根據需要自訂。
CustomerResource.php
├── CustomerResource/
├──── Pages/
│ ├── CreateCustomer.php (新建頁,預設生成)
│ ├── EditCustomer.php (編輯頁,預設生成)
│ ├── ListCustomer.php (列表頁,預設生成)
│ └── ViewCustomers.php (檢視頁)
● form() 方法:為新建和編輯頁面建立表單
● table() 方法:定義資源列表頁
● getRelations() 方法:定義與當前資源相關聯的其他資源或模型的關聯
● getPages() 方法:指定資源的頁面路由
#生成完整的 Filament 資源,包含所有 CRUD 頁面和功能 php artisan make:filament-resource Customer #基於 Laravel 模型自動生成 Filament 資源,包含自動生成的 CRUD 頁面、表單和表格 php artisan make:filament-resource Customer --generate #快速產生一個功能完善的 Filament 資源,包括所需的檢視和頁面 php artisan make:filament-resource Customer --generate --view #生成簡化版本的 Filament 資源,只包含基本的 CRUD 功能 php artisan make:filament-resource Customer --simple
〈3〉Filament 資源設定值
#改變 icon protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; #選單上的名稱 protected static ?string $navigationLabel = 'Mis Clientes'; #改變麵包屑 protected static ?string $modelLabel = 'cliente'; #功能分群 protected static ?string $navigationGroup = 'Shop'; #改變網址 protected static ?string $slug = 'pending-orders'; #改變選單項目順序 protected static ?int $navigationSort = 2;
〈4〉自定義頁面:php artisan make:filament-page SortUsers --resource=UserResource --type=custom ☞ NEW in Filament 3: Infolist Builder
☞ Create Custom Pages in Filament PHP - The Easy Way
☞ Filament Custom Page Example: Invoice Preview
☞ 3 | Add Custom Page in filament panel
☞ Filament: Eager Loading in Custom Column View
☞ Filament: Repeater "Live" Form Changes with afterStateUpdated()
沒有留言: