From 143316af3bd1e74c3998d1f2e9954626628ef60f Mon Sep 17 00:00:00 2001 From: 3x1io <3x1io@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:52:44 +0000 Subject: [PATCH] Format Code --- ...1_11_23_130725_create_categories_table.php | 4 +- resources/lang/ar/messages.php | 52 ++++++++-------- resources/lang/en/messages.php | 52 ++++++++-------- src/Console/FilamentCategoriesInstall.php | 5 +- src/Filament/Resources/CategoryResource.php | 61 +++++++++---------- .../CategoryResource/Pages/CreateCategory.php | 4 +- .../CategoryResource/Pages/EditCategory.php | 5 +- .../CategoryResource/Pages/ListCategories.php | 5 +- src/FilamentCategoriesPlugin.php | 1 - src/FilamentCategoriesServiceProvider.php | 39 ++++++------ src/Models/Category.php | 26 +++----- tests/src/TestCase.php | 1 - 12 files changed, 117 insertions(+), 138 deletions(-) diff --git a/database/migrations/2021_11_23_130725_create_categories_table.php b/database/migrations/2021_11_23_130725_create_categories_table.php index aef68e4..ea817f5 100644 --- a/database/migrations/2021_11_23_130725_create_categories_table.php +++ b/database/migrations/2021_11_23_130725_create_categories_table.php @@ -1,8 +1,8 @@ [ - "title" => "التصنيفات", - "single" => "التصنيف", - "sections" => [ - "details" => [ - "title" => "تفاصيل التصنيف", - "description" => "إنشاء تصنيف جديد", - "columns" => [ - "name" => "الاسم", - "slug" => "الرابط المختصر", - "description" => "الوصف", - "icon" => "الأيقونة", - "color" => "اللون", - ] + 'category' => [ + 'title' => 'التصنيفات', + 'single' => 'التصنيف', + 'sections' => [ + 'details' => [ + 'title' => 'تفاصيل التصنيف', + 'description' => 'إنشاء تصنيف جديد', + 'columns' => [ + 'name' => 'الاسم', + 'slug' => 'الرابط المختصر', + 'description' => 'الوصف', + 'icon' => 'الأيقونة', + 'color' => 'اللون', + ], ], - "status" => [ - "title" => "الحالة", - "description" => "إعدادات الحالة", - "columns" => [ - "parent_id" => "الأب", - "type" => "النوع", - "for" => "لـ", - "is_active" => "نشط", - "show_in_menu" => "إظهار في القائمة", - ] - ] - ] + 'status' => [ + 'title' => 'الحالة', + 'description' => 'إعدادات الحالة', + 'columns' => [ + 'parent_id' => 'الأب', + 'type' => 'النوع', + 'for' => 'لـ', + 'is_active' => 'نشط', + 'show_in_menu' => 'إظهار في القائمة', + ], + ], + ], ], ]; diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 6d6660e..bf82bf9 100644 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -1,32 +1,32 @@ [ - "title" => "Categories", - "single" => "Category", - "sections" => [ - "details" => [ - "title" => "Category Details", - "description" => "Create a new category", - "columns" => [ - "name" => "Name", - "slug" => "Slug", - "description" => "Description", - "icon" => "Icon", - "color" => "Color", - ] + 'category' => [ + 'title' => 'Categories', + 'single' => 'Category', + 'sections' => [ + 'details' => [ + 'title' => 'Category Details', + 'description' => 'Create a new category', + 'columns' => [ + 'name' => 'Name', + 'slug' => 'Slug', + 'description' => 'Description', + 'icon' => 'Icon', + 'color' => 'Color', + ], ], - "status" => [ - "title" => "Status", - "description" => "Status settings", - "columns" => [ - "parent_id" => "Parent", - "type" => "Type", - "for" => "For", - "is_active" => "Is Active", - "show_in_menu" => "Show In Menu", - ] - ] - ] + 'status' => [ + 'title' => 'Status', + 'description' => 'Status settings', + 'columns' => [ + 'parent_id' => 'Parent', + 'type' => 'Type', + 'for' => 'For', + 'is_active' => 'Is Active', + 'show_in_menu' => 'Show In Menu', + ], + ], + ], ], ]; diff --git a/src/Console/FilamentCategoriesInstall.php b/src/Console/FilamentCategoriesInstall.php index b1ebd2c..ff66324 100644 --- a/src/Console/FilamentCategoriesInstall.php +++ b/src/Console/FilamentCategoriesInstall.php @@ -28,7 +28,6 @@ public function __construct() parent::__construct(); } - /** * Execute the console command. * @@ -37,8 +36,8 @@ public function __construct() public function handle() { $this->info('Publish Vendor Assets'); - $this->artisanCommand(["migrate"]); - $this->artisanCommand(["optimize"]); + $this->artisanCommand(['migrate']); + $this->artisanCommand(['optimize']); $this->info('Filament Categories installed successfully.'); } } diff --git a/src/Filament/Resources/CategoryResource.php b/src/Filament/Resources/CategoryResource.php index 0e77cb0..c78af1a 100644 --- a/src/Filament/Resources/CategoryResource.php +++ b/src/Filament/Resources/CategoryResource.php @@ -2,19 +2,16 @@ namespace TomatoPHP\FilamentCategories\Filament\Resources; -use Filament\Resources\Concerns\Translatable; -use Illuminate\Support\Str; -use TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource\Pages; -use TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource\RelationManagers; -use TomatoPHP\FilamentCategories\Models\Category; use Filament\Forms; use Filament\Forms\Form; +use Filament\Resources\Concerns\Translatable; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; -use TomatoPHP\FilamentCategories\Models\Post; +use Illuminate\Support\Str; +use TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource\Pages; +use TomatoPHP\FilamentCategories\Models\Category; use TomatoPHP\FilamentCategories\Services\FilamentCMSTypes; use TomatoPHP\FilamentIcons\Components\IconColumn; use TomatoPHP\FilamentIcons\Components\IconPicker; @@ -63,7 +60,7 @@ public static function form(Form $form): Form ->description(trans('filament-cms::messages.content.category.sections.details.description')) ->schema([ Forms\Components\TextInput::make('name') - ->afterStateUpdated( fn(Forms\Get $get, Forms\Set $set)=> $set('slug', Str::of($get('name'))->replace(' ', '-')->lower()->toString())) + ->afterStateUpdated(fn (Forms\Get $get, Forms\Set $set) => $set('slug', Str::of($get('name'))->replace(' ', '-')->lower()->toString())) ->label(trans('filament-cms::messages.content.category.sections.details.columns.name')) ->lazy() ->required(), @@ -77,7 +74,7 @@ public static function form(Form $form): Form IconPicker::make('icon') ->label(trans('filament-cms::messages.content.category.sections.details.columns.icon')), Forms\Components\ColorPicker::make('color') - ->label(trans('filament-cms::messages.content.category.sections.details.columns.color')) + ->label(trans('filament-cms::messages.content.category.sections.details.columns.color')), ]) ->columns(2), Forms\Components\Section::make(trans('filament-cms::messages.content.posts.sections.images.title')) @@ -111,23 +108,23 @@ public static function form(Form $form): Form ->label(trans('filament-cms::messages.content.category.sections.status.columns.for')) ->searchable() ->live() - ->options(fn() => FilamentCMSTypes::getOptions()->pluck('label', 'key')->toArray()) + ->options(fn () => FilamentCMSTypes::getOptions()->pluck('label', 'key')->toArray()) ->default('post'), Forms\Components\Select::make('type') - ->hidden(function(Forms\Get $get){ + ->hidden(function (Forms\Get $get) { $for = FilamentCMSTypes::getOptions()->where('key', $get('for'))->first(); - if($for && count($for->sub)){ + if ($for && count($for->sub)) { return false; } }) ->label(trans('filament-cms::messages.content.category.sections.status.columns.type')) ->searchable() - ->options(fn(Forms\Get $get) => FilamentCMSTypes::getOptions()->where('key', $get('for'))->first()?->getSub()->pluck('label', 'key')->toArray()) + ->options(fn (Forms\Get $get) => FilamentCMSTypes::getOptions()->where('key', $get('for'))->first()?->getSub()->pluck('label', 'key')->toArray()) ->default('category'), Forms\Components\Select::make('parent_id') ->label(trans('filament-cms::messages.content.category.sections.status.columns.parent_id')) ->searchable() - ->options(fn() => Category::query()->pluck('name', 'id')->toArray()), + ->options(fn () => Category::query()->pluck('name', 'id')->toArray()), Forms\Components\Toggle::make('is_active') ->label(trans('filament-cms::messages.content.category.sections.status.columns.is_active')), Forms\Components\Toggle::make('show_in_menu') @@ -137,8 +134,8 @@ public static function form(Form $form): Form 'sm' => 1, 'md' => 2, 'lg' => 4, - ]) - ]) + ]), + ]), ]); } @@ -148,21 +145,21 @@ public static function table(Table $table): Table ->columns([ Tables\Columns\SpatieMediaLibraryImageColumn::make('feature_image') ->label(trans('filament-cms::messages.content.posts.sections.images.columns.feature_image')) - ->defaultImageUrl(fn(Category $category)=> 'https://ui-avatars.com/api/?name='.Str::of($category->slug)->replace('-','+').'&color=FFFFFF&background=020617') + ->defaultImageUrl(fn (Category $category) => 'https://ui-avatars.com/api/?name=' . Str::of($category->slug)->replace('-', '+') . '&color=FFFFFF&background=020617') ->square() ->collection('feature_image'), Tables\Columns\TextColumn::make('name') - ->description(fn(Category $category)=> Str::of($category->description)->limit(50)) + ->description(fn (Category $category) => Str::of($category->description)->limit(50)) ->label(trans('filament-cms::messages.content.category.sections.details.columns.name')) ->searchable(), Tables\Columns\TextColumn::make('for') - ->state(function (Category $category){ + ->state(function (Category $category) { return FilamentCMSTypes::getOptions()->where('key', $category->for)->first()?->label; }) - ->color(function (Category $category){ + ->color(function (Category $category) { return FilamentCMSTypes::getOptions()->where('key', $category->for)->first()?->color; }) - ->icon(function (Category $category){ + ->icon(function (Category $category) { return FilamentCMSTypes::getOptions()->where('key', $category->for)->first()?->icon; }) ->badge() @@ -170,13 +167,13 @@ public static function table(Table $table): Table ->label(trans('filament-cms::messages.content.category.sections.status.columns.for')) ->searchable(), Tables\Columns\TextColumn::make('type') - ->state(function (Category $category){ + ->state(function (Category $category) { return FilamentCMSTypes::getOptions()->where('key', $category->for)->first()?->getSub()->where('key', $category->type)->first()?->label; }) - ->color(function (Category $category){ + ->color(function (Category $category) { return FilamentCMSTypes::getOptions()->where('key', $category->for)->first()?->getSub()->where('key', $category->type)->first()?->color; }) - ->icon(function (Category $category){ + ->icon(function (Category $category) { return FilamentCMSTypes::getOptions()->where('key', $category->for)->first()?->getSub()->where('key', $category->type)->first()?->icon; }) ->badge() @@ -217,29 +214,29 @@ public static function table(Table $table): Table ->label(trans('filament-cms::messages.content.category.sections.status.columns.for')) ->searchable() ->live() - ->options(fn() => FilamentCMSTypes::getOptions()->pluck('label', 'key')->toArray()), + ->options(fn () => FilamentCMSTypes::getOptions()->pluck('label', 'key')->toArray()), Forms\Components\Select::make('type') - ->hidden(function(Forms\Get $get){ + ->hidden(function (Forms\Get $get) { $for = FilamentCMSTypes::getOptions()->where('key', $get('for'))->first(); - if($for && count($for->sub)){ + if ($for && count($for->sub)) { return false; } }) ->label(trans('filament-cms::messages.content.category.sections.status.columns.type')) ->searchable() - ->options(fn(Forms\Get $get) => FilamentCMSTypes::getOptions()->where('key', $get('for'))->first()?->getSub()->pluck('label', 'key')->toArray()), + ->options(fn (Forms\Get $get) => FilamentCMSTypes::getOptions()->where('key', $get('for'))->first()?->getSub()->pluck('label', 'key')->toArray()), ]) - ->query(function (Builder $query, array $data){ + ->query(function (Builder $query, array $data) { $query->when( $data['for'], - fn(Builder $query, $for) => $query->where('for', $for) + fn (Builder $query, $for) => $query->where('for', $for) )->when( $data['type'], - fn(Builder $query, $type) => $query->where('type', $type) + fn (Builder $query, $type) => $query->where('type', $type) ); }), - Tables\Filters\TrashedFilter::make() + Tables\Filters\TrashedFilter::make(), ]) ->actions([ Tables\Actions\ViewAction::make() diff --git a/src/Filament/Resources/CategoryResource/Pages/CreateCategory.php b/src/Filament/Resources/CategoryResource/Pages/CreateCategory.php index 3f66418..a933568 100644 --- a/src/Filament/Resources/CategoryResource/Pages/CreateCategory.php +++ b/src/Filament/Resources/CategoryResource/Pages/CreateCategory.php @@ -2,9 +2,9 @@ namespace TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource\Pages; -use TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource; use Filament\Actions; use Filament\Resources\Pages\CreateRecord; +use TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource; class CreateCategory extends CreateRecord { @@ -15,7 +15,7 @@ class CreateCategory extends CreateRecord protected function getHeaderActions(): array { return [ - Actions\LocaleSwitcher::make() + Actions\LocaleSwitcher::make(), ]; } } diff --git a/src/Filament/Resources/CategoryResource/Pages/EditCategory.php b/src/Filament/Resources/CategoryResource/Pages/EditCategory.php index 7f26fbe..56c95b4 100644 --- a/src/Filament/Resources/CategoryResource/Pages/EditCategory.php +++ b/src/Filament/Resources/CategoryResource/Pages/EditCategory.php @@ -2,9 +2,9 @@ namespace TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource\Pages; -use TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource; use Filament\Actions; use Filament\Resources\Pages\EditRecord; +use TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource; class EditCategory extends EditRecord { @@ -12,12 +12,11 @@ class EditCategory extends EditRecord protected static string $resource = CategoryResource::class; - protected function getHeaderActions(): array { return [ Actions\DeleteAction::make(), - Actions\LocaleSwitcher::make() + Actions\LocaleSwitcher::make(), ]; } } diff --git a/src/Filament/Resources/CategoryResource/Pages/ListCategories.php b/src/Filament/Resources/CategoryResource/Pages/ListCategories.php index 6496bc4..bd58975 100644 --- a/src/Filament/Resources/CategoryResource/Pages/ListCategories.php +++ b/src/Filament/Resources/CategoryResource/Pages/ListCategories.php @@ -2,9 +2,9 @@ namespace TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource\Pages; -use TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource; use Filament\Actions; use Filament\Resources\Pages\ListRecords; +use TomatoPHP\FilamentCategories\Filament\Resources\CategoryResource; class ListCategories extends ListRecords { @@ -12,12 +12,11 @@ class ListCategories extends ListRecords protected static string $resource = CategoryResource::class; - protected function getHeaderActions(): array { return [ Actions\CreateAction::make(), - Actions\LocaleSwitcher::make() + Actions\LocaleSwitcher::make(), ]; } } diff --git a/src/FilamentCategoriesPlugin.php b/src/FilamentCategoriesPlugin.php index e2926db..024dc95 100644 --- a/src/FilamentCategoriesPlugin.php +++ b/src/FilamentCategoriesPlugin.php @@ -7,7 +7,6 @@ class FilamentCategoriesPlugin implements Plugin { - public function getId(): string { return 'filament-categories'; diff --git a/src/FilamentCategoriesServiceProvider.php b/src/FilamentCategoriesServiceProvider.php index 0833f40..367a3f3 100644 --- a/src/FilamentCategoriesServiceProvider.php +++ b/src/FilamentCategoriesServiceProvider.php @@ -4,50 +4,49 @@ use Illuminate\Support\ServiceProvider; - class FilamentCategoriesServiceProvider extends ServiceProvider { public function register(): void { //Register generate command $this->commands([ - \TomatoPHP\FilamentCategories\Console\FilamentCategoriesInstall::class, + \TomatoPHP\FilamentCategories\Console\FilamentCategoriesInstall::class, ]); - + //Register Config file - $this->mergeConfigFrom(__DIR__.'/../config/filament-categories.php', 'filament-categories'); - + $this->mergeConfigFrom(__DIR__ . '/../config/filament-categories.php', 'filament-categories'); + //Publish Config $this->publishes([ - __DIR__.'/../config/filament-categories.php' => config_path('filament-categories.php'), + __DIR__ . '/../config/filament-categories.php' => config_path('filament-categories.php'), ], 'filament-categories-config'); - + //Register Migrations - $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); - + $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); + //Publish Migrations $this->publishes([ - __DIR__.'/../database/migrations' => database_path('migrations'), + __DIR__ . '/../database/migrations' => database_path('migrations'), ], 'filament-categories-migrations'); //Register views - $this->loadViewsFrom(__DIR__.'/../resources/views', 'filament-categories'); - + $this->loadViewsFrom(__DIR__ . '/../resources/views', 'filament-categories'); + //Publish Views $this->publishes([ - __DIR__.'/../resources/views' => resource_path('views/vendor/filament-categories'), + __DIR__ . '/../resources/views' => resource_path('views/vendor/filament-categories'), ], 'filament-categories-views'); - + //Register Langs - $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'filament-categories'); - + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'filament-categories'); + //Publish Lang $this->publishes([ - __DIR__.'/../resources/lang' => base_path('lang/vendor/filament-categories'), + __DIR__ . '/../resources/lang' => base_path('lang/vendor/filament-categories'), ], 'filament-categories-lang'); - + //Register Routes - $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); - + $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); + } public function boot(): void diff --git a/src/Models/Category.php b/src/Models/Category.php index c17b0f6..f686479 100644 --- a/src/Models/Category.php +++ b/src/Models/Category.php @@ -12,8 +12,8 @@ use Spatie\Translatable\HasTranslations; /** - * @property integer $id - * @property integer $parent_id + * @property int $id + * @property int $parent_id * @property string $for * @property string $type * @property string $name @@ -21,20 +21,20 @@ * @property string $description * @property string $icon * @property string $color - * @property boolean $is_active - * @property boolean $show_in_menu + * @property bool $is_active + * @property bool $show_in_menu * @property string $created_at * @property string $updated_at */ class Category extends Model implements HasMedia { - use InteractsWithMedia; use HasTranslations; + use InteractsWithMedia; use SoftDeletes; public $translatable = [ 'name', - 'description' + 'description', ]; /** @@ -52,38 +52,26 @@ class Category extends Model implements HasMedia 'is_active', 'show_in_menu', 'created_at', - 'updated_at' + 'updated_at', ]; - protected $casts = [ 'is_active' => 'boolean', 'show_in_menu' => 'boolean', ]; - /** - * @return ?BelongsTo - */ public function team(): ?BelongsTo { return class_exists(Team::class) ? $this->belongsTo(Team::class) : null; } - /** - * @return HasMany - */ public function children(): HasMany { return $this->hasMany('TomatoPHP\FilamentCategories\Models\Category', 'parent_id'); } - - /** - * @return BelongsTo - */ public function parent(): BelongsTo { return $this->belongsTo('TomatoPHP\FilamentCategories\Models\Category', 'parent_id'); } - } diff --git a/tests/src/TestCase.php b/tests/src/TestCase.php index eae04e1..fd28fd3 100644 --- a/tests/src/TestCase.php +++ b/tests/src/TestCase.php @@ -16,7 +16,6 @@ use Orchestra\Testbench\TestCase as BaseTestCase; use RyanChandler\BladeCaptureDirective\BladeCaptureDirectiveServiceProvider; use TomatoPHP\FilamentCategories\FilamentCategoriesServiceProvider; -use TomatoPHP\FilamentCategories\Tests\Models\User; abstract class TestCase extends BaseTestCase {