|
1 | 1 | # Upgrading |
2 | 2 |
|
| 3 | +## From 9.x to 10.x |
| 4 | + |
| 5 | +### New Features |
| 6 | + |
| 7 | +#### Modern Model Definition with PHP Attributes |
| 8 | + |
| 9 | +Laravel Restify v10 introduces a modern way to define models using PHP 8+ attributes. While your existing static property approach will continue to work, we recommend migrating to the new attribute-based syntax for better developer experience. |
| 10 | + |
| 11 | +**Before (v9 and earlier):** |
| 12 | +```php |
| 13 | +class UserRepository extends Repository |
| 14 | +{ |
| 15 | + public static string $model = User::class; |
| 16 | + |
| 17 | + public function fields(RestifyRequest $request): array |
| 18 | + { |
| 19 | + return [ |
| 20 | + field('name'), |
| 21 | + field('email'), |
| 22 | + ]; |
| 23 | + } |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +**After (v10 - Recommended):** |
| 28 | +```php |
| 29 | +use Binaryk\LaravelRestify\Attributes\Model; |
| 30 | + |
| 31 | +#[Model(User::class)] |
| 32 | +class UserRepository extends Repository |
| 33 | +{ |
| 34 | + public function fields(RestifyRequest $request): array |
| 35 | + { |
| 36 | + return [ |
| 37 | + field('name'), |
| 38 | + field('email'), |
| 39 | + ]; |
| 40 | + } |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +**Benefits of migrating to attributes:** |
| 45 | +- 🎯 **Modern, declarative approach** - More intuitive and cleaner code |
| 46 | +- 🔍 **Better IDE support** - Enhanced autocompletion and static analysis |
| 47 | +- 📦 **Type-safe** - Use `::class` syntax for better refactoring support |
| 48 | +- 🔧 **More discoverable** - Attributes are easier to find with reflection tools |
| 49 | +- 🚀 **Future-proof** - Follows modern PHP practices |
| 50 | + |
| 51 | +**Migration Strategy:** |
| 52 | + |
| 53 | +1. **No immediate action required** - All existing repositories continue to work as-is |
| 54 | +2. **Gradual migration** - Update repositories one at a time when convenient |
| 55 | +3. **Mixed approach** - You can use both attributes and static properties in the same codebase |
| 56 | + |
| 57 | +**Priority order for model resolution:** |
| 58 | +1. `#[Model]` attribute (highest priority) |
| 59 | +2. `public static string $model` property |
| 60 | +3. Auto-guessing from repository class name (lowest priority) |
| 61 | + |
| 62 | +This change is **100% backward compatible** - no existing code will break. |
| 63 | + |
| 64 | +#### Improved Field-Level Search and Sorting |
| 65 | + |
| 66 | +Laravel Restify v10 introduces a more intuitive way to define searchable and sortable fields directly on the field definitions. While the static array approach continues to work, the new field-level methods provide better organization and discoverability. |
| 67 | + |
| 68 | +**Before (v9 and earlier):** |
| 69 | +```php |
| 70 | +class UserRepository extends Repository |
| 71 | +{ |
| 72 | + public static array $search = ['name', 'email']; |
| 73 | + public static array $sort = ['name', 'email', 'created_at']; |
| 74 | + |
| 75 | + public function fields(RestifyRequest $request): array |
| 76 | + { |
| 77 | + return [ |
| 78 | + field('name'), |
| 79 | + field('email'), |
| 80 | + field('created_at'), |
| 81 | + ]; |
| 82 | + } |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +**After (v10 - Recommended):** |
| 87 | +```php |
| 88 | +#[Model(User::class)] |
| 89 | +class UserRepository extends Repository |
| 90 | +{ |
| 91 | + public function fields(RestifyRequest $request): array |
| 92 | + { |
| 93 | + return [ |
| 94 | + field('name')->searchable()->sortable(), |
| 95 | + field('email')->searchable()->sortable(), |
| 96 | + field('created_at')->sortable(), |
| 97 | + ]; |
| 98 | + } |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +**Benefits of field-level configuration:** |
| 103 | +- 📍 **Co-located configuration** - Search/sort behavior defined alongside the field |
| 104 | +- 🔍 **Better discoverability** - Easy to see which fields are searchable/sortable at a glance |
| 105 | +- 🎛️ **More granular control** - Configure search and sort behavior per field |
| 106 | +- 🧹 **Cleaner repositories** - Reduces static array properties |
| 107 | +- 💡 **IDE-friendly** - Better autocompletion and method chaining |
| 108 | + |
| 109 | +**Migration Strategy:** |
| 110 | + |
| 111 | +1. **Static arrays still work** - No need to change existing repositories immediately |
| 112 | +2. **Field-level takes precedence** - If both are defined, field-level configuration wins |
| 113 | +3. **Gradual migration** - Update fields one at a time or per repository |
| 114 | +4. **Mixed approach** - You can use both approaches in the same codebase during transition |
| 115 | + |
| 116 | +**Priority order for search/sort resolution:** |
| 117 | +1. Field-level `->searchable()`/`->sortable()` methods (highest priority) |
| 118 | +2. Static `$search`/`$sort` arrays (fallback) |
| 119 | + |
| 120 | +This change is also **100% backward compatible** - existing static arrays continue to work perfectly. |
| 121 | + |
| 122 | +### Configuration File Updates |
| 123 | + |
| 124 | +When upgrading to v10, it's important to ensure your local `config/restify.php` file includes all the new configuration options that have been added. |
| 125 | + |
| 126 | +**Recommended Steps:** |
| 127 | + |
| 128 | +1. **Compare configuration files** - Check your local `config/restify.php` against the latest version |
| 129 | +2. **Review new sections** - Look for new configuration options that may have been added |
| 130 | +3. **Merge changes** - Add any missing configuration sections to your local file |
| 131 | + |
| 132 | +**New configuration sections in v10 may include:** |
| 133 | + |
| 134 | +```php |
| 135 | +// Example new sections (check the actual config file for current options) |
| 136 | +'mcp' => [ |
| 137 | + 'tools' => [ |
| 138 | + 'exclude' => [], |
| 139 | + 'include' => [], |
| 140 | + ], |
| 141 | + 'resources' => [ |
| 142 | + 'exclude' => [], |
| 143 | + 'include' => [], |
| 144 | + ], |
| 145 | + 'prompts' => [ |
| 146 | + 'exclude' => [], |
| 147 | + 'include' => [], |
| 148 | + ], |
| 149 | +], |
| 150 | + |
| 151 | +'ai_solutions' => [ |
| 152 | + 'model' => 'gpt-4.1-mini', |
| 153 | + 'max_tokens' => 1000, |
| 154 | +], |
| 155 | +``` |
| 156 | + |
| 157 | +**How to update your config:** |
| 158 | + |
| 159 | +1. **Backup your current config** - Copy your existing `config/restify.php` |
| 160 | +2. **Republish the config** (optional): |
| 161 | + ```bash |
| 162 | + php artisan vendor:publish --provider="Binaryk\LaravelRestify\LaravelRestifyServiceProvider" --tag="config" --force |
| 163 | + ``` |
| 164 | +3. **Merge your custom settings** - Copy your custom values back into the new config file |
| 165 | +4. **Test your application** - Ensure all functionality works as expected |
| 166 | + |
| 167 | +<alert type="warning"> |
| 168 | +Always backup your existing configuration before making changes, especially if you have custom settings. |
| 169 | +</alert> |
| 170 | + |
3 | 171 | ## From 7.3.1 to 7.4.0 |
4 | 172 |
|
5 | 173 | ## Breaking |
|
0 commit comments