OwlCyberSecurity - MANAGER
Edit File: ProductResource.php
<?php namespace App\Filament\Resources; use App\Filament\Resources\ProductResource\Pages; use App\Filament\Resources\ProductResource\RelationManagers; use App\Helpers\Convertors; use App\Models\Article; use App\Models\Product; use Closure; use Filament\Forms; use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Grid; use Filament\Forms\Components\Section; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Support\RawJs; use Filament\Tables; use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Filters\Filter; use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Support\Str; use Mohamedsabil83\FilamentFormsTinyeditor\Components\TinyEditor; class ProductResource extends Resource { protected static ?string $model = Product::class; protected static ?string $navigationIcon = 'heroicon-o-shopping-bag'; protected static ?string $slug = 'product'; protected static ?string $modelLabel = 'محصول'; protected static ?string $pluralModelLabel = 'محصولات'; protected static ?int $navigationSort = 4; protected static ?string $navigationGroup = 'خرید اعتباری'; public static function form(Form $form): Form { return $form ->schema([ Grid::make(3)->schema([ Grid::make(1)->schema([ Grid::make(1)->schema([ TextInput::make('title')->label('عنوان')->columnSpan(2)->required(), ]), Section::make()->schema([ TextInput::make('description')->label('توضیحات')->columnSpan(2)->required(), TinyEditor::make('body')->label('متن')->fileAttachmentsDisk('public')->fileAttachmentsVisibility('public')->fileAttachmentsDirectory('uploads')->required(), ]), Section::make('سئو')->relationship('seo')->schema([ TextInput::make('title')->label('تایتل صفحه')->maxLength(255), TextInput::make('keyword')->label('کیورد صفحه')->maxLength(255), TextInput::make('description')->label('توضیحات صفحه'), // Textarea::make('description')->label('توضیحات صفحه'), ])->collapsed(), Section::make()->schema([ FileUpload::make('images')->label('آلبوم تصاویر')->multiple(), ]), ])->columnSpan(2), Section::make()->schema([ TextInput::make('slug')->label('اسلاگ')->rules([ function () { return function (string $attribute, $value, Closure $fail) { if ($value != Convertors::createSlug($value, '-')) { $fail('فرمت اسلاگ صحیح نمیباشد'); } }; }, ])->unique(ignoreRecord: true)->maxLength(255)->required(), TextInput::make('price')->label('قیمت (ریال)')->required()->minValue(0)->mask(RawJs::make('$money($input)')) ->dehydrateStateUsing(fn(string $state): string => preg_replace("/[^0-9]/", "", $state)), TextInput::make('shipping_cost')->label('هزینه ارسال (ریال)')->required()->minValue(0)->mask(RawJs::make('$money($input)')) ->dehydrateStateUsing(fn(string $state): string => preg_replace("/[^0-9]/", "", $state)), TextInput::make('code')->label('کد محصول')->unique(ignoreRecord: true)->maxLength(255)->required(), Select::make('store_id')->relationship('store', 'title')->label('انتخاب فروشگاه')->required(), Select::make('category_id')->relationship('category', 'title')->label('دسته بندی')->required(), FileUpload::make('image_name')->image()->label('تصویر شاخص')->imageEditor()->required(), Toggle::make('is_show')->label('وضعیت نمایش')->required(), TextInput::make('count')->label('تعداد موجودی')->required()->numeric(), TextInput::make('weight')->label('وزن محصول (گرم)) ')->required()->numeric(), TextInput::make('min_delivery_period')->label('حداقل زمان تحویل (روز)')->required()->numeric(), TextInput::make('max_delivery_period')->label('حداکثر زمان تحویل ( روز)')->required()->numeric(), ])->columnSpan(1), ]), ]); } public static function table(Table $table): Table { return $table ->columns([ TextColumn::make('title')->label('عنوان')->searchable(), TextColumn::make('code')->label('کد محصول')->searchable(), TextColumn::make('price')->label('قیمت (ریال)'), TextColumn::make('shipping_cost')->label('هزینه ارسال (ریال)'), // TextColumn::make('view_count')->label('تعداد نمایش'), TextColumn::make('store.title')->label(' فروشگاه'), TextColumn::make('category.title')->label('دسته بندی'), IconColumn::make('is_show')->label('وضعیت نمایش')->boolean(), TextColumn::make('created_at')->label('ایجاد در')->dateTime(), TextColumn::make('updated_at')->label('آخرین برروزرسانی')->dateTime(), ]) ->filters([ SelectFilter::make('store')->label('فروشگاه')->relationship('store', 'title'), SelectFilter::make('category')->label('دسته بندی')->relationship('category', 'title'), SelectFilter::make('is_show')->label('وضعیت نمایش')->options(['1' => 'بله', '0' => 'خیر']), ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ // Tables\Actions\DeleteBulkAction::make(), ]), ])->defaultSort('updated_at', 'desc'); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListProducts::route('/'), 'create' => Pages\CreateProduct::route('/create'), 'edit' => Pages\EditProduct::route('/{record}/edit'), ]; } public static function canViewAny(): bool { return auth()->user()->can('product::view'); } }