-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
first commit 🔥 #2
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request updates dependency constraints in Changes
Sequence Diagram(s)sequenceDiagram
participant Plugin as FilamentCategoriesPlugin
participant Module
participant Panel
Plugin->>Module: Check if FilamentCategories module exists & enabled?
Module-->>Plugin: (Result)
Plugin->>Plugin: Set isActive flag (always true)
Plugin->>Panel: Register CategoryResource & CategoriesMetaResource
sequenceDiagram
participant User
participant Panel as Filament Panel
participant Resource as Category/Meta Resource
User->>Panel: Navigate to resource listing
Panel->>Resource: Load List View
User->>Panel: Click "Create" Action
Panel->>Resource: Load Create Page
User->>Panel: Select record to edit
Panel->>Resource: Load Edit Page
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command ✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Nitpick comments (16)
resources/lang/en/messages.php (1)
30-37
: Inconsistent quote style in new section.The new "images" section uses double quotes while the rest of the file uses single quotes. Consider using single quotes consistently throughout the file.
- "images" => [ - "title" => "Images", - "description" => "Images settings", - "columns" => [ - "feature_image" => "Feature Image", - "cover_image" => "Cover Image", - ] - ], + 'images' => [ + 'title' => 'Images', + 'description' => 'Images settings', + 'columns' => [ + 'feature_image' => 'Feature Image', + 'cover_image' => 'Cover Image', + ] + ],resources/lang/ar/messages.php (1)
30-37
: Inconsistent quote style in new section.The new "images" section uses double quotes while the rest of the file uses single quotes. Consider using single quotes consistently throughout the file.
- "images" => [ - "title" => "الصور", - "description" => "إعدادات الصور", - "columns" => [ - "feature_image" => "صورة مميزة", - "cover_image" => "صورة الغلاف", - ] - ], + 'images' => [ + 'title' => 'الصور', + 'description' => 'إعدادات الصور', + 'columns' => [ + 'feature_image' => 'صورة مميزة', + 'cover_image' => 'صورة الغلاف', + ] + ],src/Filament/Resources/CategoriesMetaResource/Pages/ListCategoriesMetas.php (1)
9-19
: Consider simplifying the class name.The class name
ListCategoriesMetas
contains a double plural with both "Categories" and "Metas". Consider usingListCategoryMeta
or simplyListMetas
for better clarity.Otherwise, the implementation correctly follows Filament's patterns for list pages with appropriate header actions.
src/Models/CategoryMeta.php (3)
18-18
: Consider renaming the class to match the file name.The class name
CategoriesMeta
(plural 'Categories') doesn't match the file nameCategoryMeta.php
(singular 'Category'). For consistency with Laravel conventions, model class names are typically singular.-class CategoriesMeta extends Model +class CategoryMeta extends Model
23-23
: Consider adding table name property.Laravel will default the table name to
categories_metas
based on the class name. If your database table has a different name, you should explicitly define it with the$table
property.protected $fillable = ['category_id', 'model_id', 'model_type', 'key', 'value', 'created_at', 'updated_at']; +/** + * @var string + */ +protected $table = 'category_metas';
1-32
: Add polymorphic relationship method for model_id and model_type fields.Your model has
model_id
andmodel_type
fields which suggest a polymorphic relationship, but there's no corresponding method defined. Consider adding amorphTo
relationship for better Laravel integration.public function category() { return $this->belongsTo('TomatoPHP\FilamentCategories\Models\Category'); } +/** + * Get the parent model that the meta belongs to. + * + * @return \Illuminate\Database\Eloquent\Relations\MorphTo + */ +public function model() +{ + return $this->morphTo(); +}src/Services/FilamentCategoriesTypes.php (3)
5-6
: Unused import.
Illuminate\Support\Str
is imported but not used in this class.-use Illuminate\Support\Str;
12-22
: Add validation to ensure duplicate types aren't registered.The current implementation allows registering the same category type multiple times. Consider adding validation to prevent duplicates based on the type's key.
public static function register(CategoriesType|array $categoriesType) { if(is_array($categoriesType)) { foreach($categoriesType as $type) { self::register($type); } return; } + // Prevent duplicates based on key + foreach(self::$categoriesTypes as $existingType) { + if($existingType->key === $categoriesType->key) { + return; + } + } self::$categoriesTypes[] = $categoriesType; }
24-27
: Add method to retrieve a specific category type by key.Currently, there's no way to retrieve a specific category type without filtering the collection. Consider adding a helper method for this common operation.
public static function getOptions() { return collect(self::$categoriesTypes); } +/** + * Get a specific category type by key + * + * @param string $key + * @return CategoriesType|null + */ +public static function getType(string $key) +{ + foreach(self::$categoriesTypes as $type) { + if($type->key === $key) { + return $type; + } + } + + return null; +}src/Filament/Resources/CategoriesMetaResource.php (3)
20-20
: Add meaningful navigation icon and labels.The current navigation icon is generic. Consider using a more specific icon and adding navigation labels to improve usability.
protected static ?string $model = CategoriesMeta::class; -protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; +protected static ?string $navigationIcon = 'heroicon-o-tag'; +protected static ?string $navigationLabel = 'Categories Meta'; +protected static ?string $modelLabel = 'Category Meta'; +protected static ?string $pluralModelLabel = 'Categories Meta';
36-36
: Enhance the value field to support different data types.The current
value
field is a simple text input. Consider using a more flexible approach to handle different data types.-Forms\Components\TextInput::make('value'), +Forms\Components\Textarea::make('value') + ->columnSpanFull() + ->hint('This field supports various data types depending on the key'),
63-65
: Add filters for improving data management.The table currently has no filters. Adding filters for key fields would improve usability.
->filters([ - // + Tables\Filters\SelectFilter::make('category_id') + ->relationship('category', 'name') + ->searchable() + ->label('Category'), + Tables\Filters\Filter::make('key') + ->form([ + Forms\Components\TextInput::make('key') + ->label('Key') + ->placeholder('Search by key'), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query + ->when( + $data['key'], + fn (Builder $query, $key): Builder => $query->where('key', 'like', "%{$key}%"), + ); + }), ])src/Services/Contracts/CategoriesType.php (4)
6-7
: Remove unused import.The
Illuminate\Support\Facades\Cookie
facade is imported but not used in the class.use Illuminate\Support\Collection; -use Illuminate\Support\Facades\Cookie; use Illuminate\Support\Str;
9-23
: Fix method annotations in PHPDoc.The PHPDoc
@method
annotations don't match the actual method signatures. They're missing return types./** * * Class CategoriesType * @package TomatoPHP\FilamentCategories\Services\Contracts * @property string $key * @property string $label * @property string $icon * @property string $color -* @method static make(string $key) -* @method key(string $key) -* @method label(string $label) -* @method icon(string $icon) -* @method color(string $color) +* @method static self make(string $key) +* @method self key(string $key) +* @method self label(string $label) +* @method self icon(string $icon) +* @method self color(string $color) +* @method self sub(array $sub) +* @method Collection getSub() +* @method array toArray() * */
49-49
: Fix PHPDoc return type.The PHPDoc return type is incorrect. It should be
self
instead ofvoid
./** * @param string $key -* @return void +* @return self */
117-126
: Implement ArrayAccess or Arrayable interfaces.For better Laravel integration, consider implementing
Arrayable
interface to make this class work seamlessly with Laravel's collection methods.+ use Illuminate\Contracts\Support\Arrayable; /** * ... */ -class CategoriesType +class CategoriesType implements Arrayable { // ... /** * @return array */ public function toArray() { return [ 'key' => $this->key, 'label' => $this->label, 'icon' => $this->icon, 'color' => $this->color, 'sub' => $this->sub, ]; } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (18)
composer.json
(1 hunks)database/migrations/2025_02_26_103918_create_categories_table.php
(2 hunks)database/migrations/2025_02_26_104057_create_category_metas_table.php
(1 hunks)resources/lang/ar/messages.php
(1 hunks)resources/lang/en/messages.php
(1 hunks)src/Filament/Resources/CategoriesMetaResource.php
(1 hunks)src/Filament/Resources/CategoriesMetaResource/Pages/CreateCategoriesMeta.php
(1 hunks)src/Filament/Resources/CategoriesMetaResource/Pages/EditCategoriesMeta.php
(1 hunks)src/Filament/Resources/CategoriesMetaResource/Pages/ListCategoriesMetas.php
(1 hunks)src/Filament/Resources/CategoryResource.php
(7 hunks)src/Filament/Resources/CategoryResource/Pages/CreateCategory.php
(2 hunks)src/Filament/Resources/CategoryResource/Pages/EditCategory.php
(1 hunks)src/Filament/Resources/CategoryResource/Pages/ListCategories.php
(1 hunks)src/FilamentCategoriesPlugin.php
(2 hunks)src/Models/Category.php
(2 hunks)src/Models/CategoryMeta.php
(1 hunks)src/Services/Contracts/CategoriesType.php
(1 hunks)src/Services/FilamentCategoriesTypes.php
(1 hunks)
✅ Files skipped from review due to trivial changes (3)
- src/Filament/Resources/CategoryResource/Pages/ListCategories.php
- src/Filament/Resources/CategoryResource/Pages/EditCategory.php
- src/Filament/Resources/CategoryResource/Pages/CreateCategory.php
🧰 Additional context used
🪛 GitHub Actions: Tests
composer.json
[error] 1-1: Your requirements could not be resolved to an installable set of packages.
[error] 1-1: Root composer.json requires filament/filament ^3.23, found filament/filament[3.x-dev] but it does not match your minimum-stability.
🔇 Additional comments (21)
src/Filament/Resources/CategoriesMetaResource/Pages/CreateCategoriesMeta.php (1)
1-12
: Correct implementation of Filament CreateRecord page.The class is properly structured and follows Filament's recommended patterns for creating resource pages. The implementation is minimal but complete for standard CRUD operations.
src/Filament/Resources/CategoriesMetaResource/Pages/EditCategoriesMeta.php (1)
1-19
: Looks good - standard Filament edit page implementationThe
EditCategoriesMeta
class correctly extends Filament'sEditRecord
class and follows the standard structure for a Filament resource edit page. The implementation of thegetHeaderActions
method properly returns a delete action.database/migrations/2025_02_26_104057_create_category_metas_table.php (1)
1-37
: Migration schema follows Laravel conventions but has a future dateThe migration properly creates the
category_metas
table with appropriate columns and relationships. However, the migration filename contains a future date (2025). While this won't affect functionality, it could cause confusion with migration ordering.Also, verify whether the table name should be
category_metas
orcategories_meta
to ensure consistency with your naming conventions.database/migrations/2025_02_26_103918_create_categories_table.php (3)
12-12
: Good addition of return typeAdding the void return type follows modern PHP type hinting practices and improves code clarity.
17-19
: Good addition of foreign key constraintThe foreign key constraint properly links the
team_id
column to theteams
table with cascade deletion, which helps maintain database integrity.
41-41
: Good addition of return typeAdding the void return type follows modern PHP type hinting practices and improves code clarity.
src/FilamentCategoriesPlugin.php (3)
7-8
: Resource imports added correctlyThe imports for the required resources are properly added.
12-13
: Private property added correctlyThe
$isActive
boolean property is properly defined.
28-33
: Resources registration looks goodThe conditional registration of resources is implemented correctly.
src/Models/Category.php (4)
13-29
: Good update to property type annotations.The docblock now uses more precise type declarations (
integer
andboolean
) and adds new relationship properties that provide better documentation for the model structure.
34-40
: Description field is now translatable.Adding 'description' to the translatable array is a good improvement for multilingual support.
66-69
: Simplified Team relationship implementation.The team method has been simplified to directly return the belongsTo relationship without checking for the existence of the Team class.
83-90
: Good addition of CategoriesMetas relationship.The new categoriesMetas relationship properly establishes the connection with the CategoriesMeta model, supporting the new metadata structure mentioned in the PR.
src/Filament/Resources/CategoryResource.php (6)
5-19
: Appropriate updates to imports.Good reorganization of imports, including the shift from FilamentCMSTypes to FilamentCategoriesTypes, which aligns with the architectural changes in this PR.
30-48
: Consistent update to translation namespaces.Translation keys have been consistently updated from 'filament-cms::messages' to 'filament-categories::messages', reflecting the shift to a more focused category management system.
110-126
: Properly integrated FilamentCategoriesTypes service.The code now correctly uses the FilamentCategoriesTypes service for managing category types, replacing the previous FilamentCMSTypes service.
159-167
: Consistent update of service methods in table columns.The 'for' column state and styling now properly utilize the new FilamentCategoriesTypes service.
173-181
: Consistent update of service methods for the type column.The 'type' column state and styling now properly utilize the new FilamentCategoriesTypes service.
242-242
: Added support for soft deletes.Adding TrashedFilter enables filtering of soft-deleted records, improving data management capabilities.
composer.json (2)
51-51
: Update PHP version requirements.Dropping support for PHP 8.1 while adding support for PHP 8.3 and 8.4 is a forward-looking change, but ensure your users are aware of this compatibility shift.
56-65
: Update dev dependencies.Good updates to development dependencies, including moving to newer versions of testing packages. These should provide better development tools and compatibility with newer PHP versions.
if(class_exists(Module::class) && \Nwidart\Modules\Facades\Module::find('FilamentCategories')?->isEnabled()){ | ||
$this->isActive = true; | ||
} | ||
else { | ||
$this->isActive = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic issue in condition handling
The current implementation sets $isActive
to true in both the if and else branches, making the condition check ineffective.
if(class_exists(Module::class) && \Nwidart\Modules\Facades\Module::find('FilamentCategories')?->isEnabled()){
$this->isActive = true;
}
-else {
- $this->isActive = true;
-}
Also, Module
is used without an import. Consider adding:
use Nwidart\Modules\Module;
public function category() | ||
{ | ||
return $this->belongsTo('TomatoPHP\FilamentCategories\Models\Category'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use ::class notation instead of string reference for better IDE support.
Using the class name string reference is deprecated in modern Laravel applications. Using the ::class notation provides better type hinting and refactoring support.
public function category()
{
- return $this->belongsTo('TomatoPHP\FilamentCategories\Models\Category');
+ return $this->belongsTo(Category::class);
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public function category() | |
{ | |
return $this->belongsTo('TomatoPHP\FilamentCategories\Models\Category'); | |
} | |
public function category() | |
{ | |
return $this->belongsTo(Category::class); | |
} |
Forms\Components\TextInput::make('model_id') | ||
->numeric(), | ||
Forms\Components\TextInput::make('model_type') | ||
->maxLength(255), | ||
Forms\Components\TextInput::make('category_id') | ||
->required() | ||
->numeric(), | ||
Forms\Components\TextInput::make('key') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Replace numeric inputs with relationship selectors.
The current form uses basic text inputs for IDs. Using relationship selectors would improve the user experience and data integrity.
Forms\Components\TextInput::make('model_id')
->numeric(),
Forms\Components\TextInput::make('model_type')
->maxLength(255),
-Forms\Components\TextInput::make('category_id')
- ->required()
- ->numeric(),
+Forms\Components\Select::make('category_id')
+ ->relationship('category', 'name')
+ ->required()
+ ->searchable(),
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Forms\Components\TextInput::make('model_id') | |
->numeric(), | |
Forms\Components\TextInput::make('model_type') | |
->maxLength(255), | |
Forms\Components\TextInput::make('category_id') | |
->required() | |
->numeric(), | |
Forms\Components\TextInput::make('key') | |
Forms\Components\TextInput::make('model_id') | |
->numeric(), | |
Forms\Components\TextInput::make('model_type') | |
->maxLength(255), | |
Forms\Components\Select::make('category_id') | |
->relationship('category', 'name') | |
->required() | |
->searchable(), | |
Forms\Components\TextInput::make('key') |
'created_at', | ||
'updated_at', | ||
'updated_at' | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove updated_at
from fillable attributes.
Including 'updated_at' in the $fillable array might bypass Laravel's automatic timestamp handling.
protected $fillable = [
'type',
'for',
'parent_id',
'name',
'slug',
'description',
'icon',
'color',
'is_active',
'show_in_menu',
'created_at',
- 'updated_at'
];
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
'created_at', | |
'updated_at', | |
'updated_at' | |
]; | |
protected $fillable = [ | |
'type', | |
'for', | |
'parent_id', | |
'name', | |
'slug', | |
'description', | |
'icon', | |
'color', | |
'is_active', | |
'show_in_menu', | |
'created_at', | |
]; |
"tomatophp/console-helpers": "^1.1", | ||
"filament/filament": "^3.2" | ||
"filament/filament": "^3.23" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Fix dependency version constraint.
The pipeline is failing because Filament 3.23 doesn't match your minimum-stability requirements.
- "filament/filament": "^3.23"
+ "filament/filament": "^3.0"
The error suggests that version 3.23 might not be released yet or requires a development stability flag. Consider using a more conservative version constraint or adjusting the stability requirements in composer.json.
🏁 Script executed:
#!/bin/bash
# Check available Filament versions
composer show filament/filament --available
Length of output: 11555
Action Required: Update Filament Dependency Constraint
Based on the output from the composer command, it’s clear that no stable release matching the "^3.23" constraint exists. The available stable versions (like v3.3.0 and others in the 3.x series) fall under a constraint such as "^3.0". The pipeline issue arises because "^3.23" forces Composer to look for a version that isn’t available without additional stability flags.
Please update the dependency in composer.json
accordingly:
- File:
composer.json
(line 53)
- "filament/filament": "^3.23"
+ "filament/filament": "^3.0"
This change will ensure that Composer selects a published, stable version of Filament that complies with your project's minimum-stability requirements.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"filament/filament": "^3.23" | |
"filament/filament": "^3.0" |
Summary by CodeRabbit
Chores
New Features
Refactor