强烈建议社区的小伙伴一起翻译filamentphp文档,昨天使用了一下,真的很好用!

filamentphp

一个开源的laravel 后台管理

社区相当活跃,使用非常优雅、灵活、随着laravel生态一起成长

使用示例

安装完成后执行:
php artisan make:filament-resource OrderResource 创建资源

强烈建议社区的小伙伴一起翻译filamentphp文档,昨天使用了一下,真的很好用!

生成如上文件,编辑OrderResource.php

<?php

namespace App\Filament\Resources;

use App\Enums\OrderStatusEnum;
use App\Filament\Resources\OrderResource\Pages;
use App\Filament\Resources\OrderResource\RelationManagers;
use App\Models\Order;
use App\Models\Product;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use pxlrbt\FilamentExcel\Actions\Tables\ExportBulkAction;

class OrderResource extends Resource
{
    protected static ?string $model = Order::class;

    protected static ?string $navigationIcon = 'heroicon-o-shopping-bag';

    protected static ?string $navigationGroup = 'Shop';

    protected static ?int $navigationSort = 3;

    public static function getNavigationBadge(): ?string
    {
        return static::getModel()::where('status', '=', 'processing')->count();
    }

    public static function getNavigationBadgeColor(): string|array|null
    {
        return static::getModel()::where('status', '=', 'processing')->count() > 10 ? 'warning' : 'primary';
    }

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\Wizard::make([
                    Forms\Components\Wizard\Step::make('Order Details')->schema([
                        Forms\Components\TextInput::make('number')->default('OR-' . random_int(1000000, 9999999))
                        ->disabled()->dehydrated()->required()->unique(),

                        Forms\Components\Select::make('customer_id')->relationship('customer' ,'name')
                        ->searchable()->required(),

                        Forms\Components\TextInput::make('shipping_price')->label('Shipping Costs')->dehydrated()
                        ->numeric()->required(),

                        Forms\Components\Select::make('type')->options([
                            'pending' => OrderStatusEnum::PENDING->value,
                            'processing' => OrderStatusEnum::PROCESSING->value,
                            'completed' => OrderStatusEnum::COMPLETED->value,
                            'declined' => OrderStatusEnum::DECLINED->value,
                        ])->required(),

                        Forms\Components\MarkdownEditor::make('notes')->columnSpanFull()
                    ])->columns(2),

                    Forms\Components\Wizard\Step::make('Order Items')->schema([
                        Forms\Components\Repeater::make('items')->relationship()->schema([

                            Forms\Components\Select::make('product_id')->label('Product')
                                ->options(Product::query()->pluck('name', 'id'))->required()
                                ->reactive()->afterStateUpdated(fn($state, Forms\Set $set) =>
                                $set('unit_price', Product::find($state)?->price ?? 0)),

                            Forms\Components\TextInput::make('quantity')->numeric()->default(1)->required()
                            ->live()->dehydrated()->integer()->minValue(0),
                            Forms\Components\TextInput::make('unit_price')->label('Unit Price')->required()
                                ->disabled()->dehydrated()->numeric(),

                            Forms\Components\Placeholder::make('total_price')->label('Total Price')
                            ->content(fn($get) => $get('quantity') * $get('unit_price')),
                        ])->columns(4)

                    ])
                ])->columnSpanFull()
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('number')->searchable()->searchable(),
                Tables\Columns\TextColumn::make('customer.name')->searchable()->searchable()->toggleable(),
                Tables\Columns\TextColumn::make('status')->searchable()->searchable(),
                /*Tables\Columns\TextColumn::make('total_price')->searchable()->searchable()->summarize([
                    Tables\Columns\Summarizers\Sum::make()->money()
                ]),*/
                Tables\Columns\TextColumn::make('created_at')->label('Order Date')->date()
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\ActionGroup::make([
                    Tables\Actions\EditAction::make(),
                    Tables\Actions\ViewAction::make(),
                    Tables\Actions\DeleteAction::make(),
                ])
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    ExportBulkAction::make(),
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListOrders::route('/'),
            'create' => Pages\CreateOrder::route('/create'),
            'edit' => Pages\EditOrder::route('/{record}/edit'),
        ];
    }    
}

就完成了,可谓相当的好用:

强烈建议社区的小伙伴一起翻译filamentphp文档,昨天使用了一下,真的很好用!

大家一起拾柴可行?

join_jiang
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 35
翟宇鑫

感觉速度慢的离奇 :joy:
开发体验确实不错,比起 laravel-admin 有过之无不及

1年前 评论
666666 (楼主) 1年前
哪吒的狗腿子 1年前
翟宇鑫 (作者) 1年前

不好用啊 还是配合vue全家桶吧

1年前 评论
碳技术 1年前
666666 (楼主) 1年前
  • 听说过,差不多就是用 PHP 写页面,不用再单纯写 JS ? :smiling_imp:
  • Laravel-Admin 后台的区别在哪里? :hushed:
  • Filament = Laravel + Livewire + Tailwind CSS + Alpine JS ? :cow:
  • 为了中文 Laravel 环境,可以搞个文档,大家一起翻译哇 :bug:
1年前 评论
Tacks (作者) 1年前
Ailon 1年前

真是不错的东西

1年前 评论
666666 (楼主) 1年前

五天交付了一个项目。Filament + restful :kissing_heart:

1年前 评论
666666 (楼主) 1年前

我也用了两个月了,也自己弄过页面,也赞助了一些。

挺好的,怎么说呢?不管是人员帮忙解决问题,或者是更新速度,人员友好程度都不错。

就是不会 Livewire,以及一些高级用法难受一些。还要学习。

1年前 评论
666666 (楼主) 1年前

最重要的 插件市场也有的,很多插件确实不错

1年前 评论
666666 (楼主) 1年前

www.laravel-filament.cn/docs/zh-CN... 这不是有个中文网吗

1年前 评论
ltaoo 1年前
666666 (楼主) 1年前
666666 (楼主) 1年前
快乐壮

刚看了看这个东西,是不是没有权限管理啊

1年前 评论
666666 (楼主) 1年前

不太会用docker, 系统低版本,如何装PHP8? 我卡在这里

1年前 评论
666666 (楼主) 1年前
ErzaQ (作者) 1年前

有没有交流群

1年前 评论
666666 (楼主) 1年前

和 dcat admin 相比怎么样

1年前 评论
666666 (楼主) 1年前

你看 laravel-filament.cn 这是啥

1年前 评论
slowlyo

真不错 我选择更灵活的 Owl Admin ~

doge

1年前 评论

这玩意是真的难用,要不是公司用这破玩意,我都不想打开这文档。。。。。。php真的落后了,Java都前后端分离的,php还在混合开发,笑死我了,php迟早都得被淘汰

6个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!