به طور خلاصه در لاراول 10.4، ویژگیهای اصلی این نسخه شامل بهبودهایی در امنیت، پشتیبانی از ساختار مدل جدید، افزودن متد جدید در ارتباط با پایگاه داده، بهبود سیستم کشینگ و اضافه شدن تعدادی کامپوننت UI جدید است. به طور کلی، این نسخهی جدید لاراول قابلیتهای مهمی را برای توسعه دهندگان بهبود داده است.
File::json() method
Austin White یکی از contributed متد ” () File::json ” به عنوان یک ابزار ساده برای دریافت دادههای رمزگذاری شده به صورت JSON از یک فایل به پروژه لاراول اضافه کرد.
/ Before
$contents = File::get('sample.json');
$data = json_decode($contents, true);
// After
$data = File::json('sample.json');
تبدیل یک رابطه HasMany موجود به رابطه HasOne
در این آپدیت یک رابطه HasMany به HasOne و همچنین یک رابطه MorphMany به MorphOne تبدیل می شود.
برای مثال، فرض کنید که شما باید دو رابطه را تعریف کنید:
class User extends Model
{
public function logins(): HasMany {
return $this->hasMany(Login::class, 'some_id', 'the_other_id');
}
public function latestLogin(): HasOne {
return $this->hasOne(Login::class, 'some_id', 'the_other_id')->latestOfMany();
}
}
میتوانید با استفاده از متد ->one() به جای تعریف دو رابطه، عملیات مورد نظر خود را انجام دهید:
class User extends Model
{
public function logins(): HasMany {
return $this->hasMany(Login::class, 'some_id', 'the_other_id');
}
public function latestLogin(): HasOne {
return $this->logins()->one()->latestOfMany();
}
}
ایجاد متد macroable برای “paginationInformation“
در ورژن 10.4 لاراول قابلیت تعریف macro را برای “paginationInformation” اضافه شده که این امکان را برای شخص فراهم میکند تا اطلاعات صفحهبندی را به صورت سفارشی تنظیم کند.
/** @mixin \Illuminate\Http\Resources\Json\ResourceCollection */
class ResourceCollectionMixin
{
public function paginationInformation(): Closure
{
return fn ($request, $paginated, $default) => collect($default)->mapWithKeysRecursively(fn ($item, $key) => [Str::camel($key) => $item])->toArray();
}
}
سایر تغییرات
شما میتوانید لیست کاملی از ویژگیها و بهروزرسانیهای جدید را و همچنین تفاوت بین نسخه 10.3.0 و 10.4.0 را در GitHub ببینید.
ورژن 10.4.0
اضافه شده :
- Added
Illuminate/Testing/Concerns/AssertsStatusCodes::assertUnsupportedMediaType()(#46426) - Added curl_error_code: 77 to DetectsLostConnections (#46429)
- Allow for converting a HasMany to HasOne && MorphMany to MorphOne (#46443)
- Add option to create macroable method for paginationInformation (#46461)
- Added
Illuminate/Filesystem/Filesystem::json()(#46481)
درست شده :
- Fix parsed input arguments for command events using dispatcher rerouting (#46442)
- Fix enums uses with optional implicit parameters (#46483)
- Fix deprecations for embedded images in symfony mailer (#46488)
تغییر داده شده
- Added alternative database port in Postgres DSN (#46403)
- Allow calling getControllerClass on closure-based routes (#46411)
- Remove obsolete method_exists(ReflectionClass::class, ‘isEnum’) call (#46445)
- Convert eloquent builder to base builder in whereExists (#46460)
- Refactor shared static methodExcludedByOptions method to trait (#46498)
