Skip to content

Releases: dshafik/bag

Fix an issue with name mapping when running validation

10 Jan 01:34
Compare
Choose a tag to compare

What's Changed

  • fix: use input aliases for validation by @dshafik in #67

Full Changelog: 2.0.1...2.0.2

Fix a bug where route params overwrites explicitly set bag data

09 Jan 05:29
Compare
Choose a tag to compare

What's Changed

Full Changelog: 2.0.0...2.0.1

Breaking Changes: Support for Union Types & Fill Nullables

05 Jan 22:38
Compare
Choose a tag to compare

What's Changed

Breaking Changes

This release has one major breaking change, and a minor breaking change:

Casting with Union Types

To support union types fully, the \Bag\Casts\CastsPropertySet::set() method signature has changed the first argument from:

public function set(string $propertyType, string $propertyName, \Illuminate\Support\Collection $properties): mixed

to:

public function set(\Bag\Collection $propertyTypes, string $propertyName, \Illuminate\Support\Collection $properties): mixed

To update your code and retain the previous behavior, you will want to do the following:

- public function set(string $propertyType, string $propertyName, \Illuminate\Support\Collection $properties): mixed
- {
+ public function set(\Bag\Collection $propertyTypes, string $propertyName, \Illuminate\Support\Collection $properties): mixed
+ {
+       $propertyType = $propertyTypes->first();

Fill Nullables

The behavior when instantiating a Bag has changed such that arguments that are nullable without a default value are filled with nulls. Previously, this would have caused exception to be thrown. This solves for a common scenario when you are filling a Bag from user input.

readonly class MyBag extends Bag {
    public function __construct(
         public ?string $name
    }
}

// Bag 1.4.0 (and older)
MyBag::from([]); // throws MissingPropertiesException

// Bag 2.0.0+
MyBag::from([]); // MyBag { $name = null }

Full Changelog: 1.4.0...2.0.0

Manual Validation, To Collection, PHP 8.4 support, Bug Fixes

03 Jan 17:02
Compare
Choose a tag to compare

What's Changed

  • fix: use the applications Laravel validator when available by @dshafik in #60
  • feat: Add toCollection() method by @dshafik in #61
  • feat: Add better support for optional validation by @dshafik in #62
  • feat: Finalize PHP 8.4 support by @dshafik in #63

Full Changelog: 1.3.2...1.4.0

Fix handling of extra properties

06 Dec 00:07
Compare
Choose a tag to compare

What's Changed

  • fix: Allow additional object properties (fixes #54) by @dshafik in #56
  • fix: Fix phpdocs for the \Bag\Attributes\Factory constructor by @dshafik in #57

Full Changelog: 1.3.1...1.3.2

Fix Eloquent Casting for Non-Bag Values

04 Nov 19:54
0ae60b2
Compare
Choose a tag to compare

This is a bug fix release that resolves an issue where non-Bag values were cast incorrectly when using Eloquent casting

Support named and positional arguments when instantiating a Bag

30 Sep 04:45
0054e5b
Compare
Choose a tag to compare

New Features

With this release Bag now supports the ability to create new instances by passing in named or positional arguments. (docs)

To get auto-complete in your editor, you will need to add @method phpdocs to your bag class. This can be automated using artisan make:bag <Bag> --docs --update. (docs)

Full Changelog: 1.2.2...1.3.0

Fix null support for Magic Casts

26 Sep 07:00
Compare
Choose a tag to compare

Fixes

  • Fix an issue where MagicCast would error when casting to Bag objects, and would be less strict when casting to other types (i.e. it would act like strict_types was off, null -> int = 0)

Full Changelog: 1.2.1...1.2.2

Add support for Unique and Exists Validation Rules

14 Sep 04:13
Compare
Choose a tag to compare

New Features

This release adds support for Laravel's Unique and Exists database-based validations.

Migrated to Pest tests, Initial PHP 8.4 support

12 Sep 12:15
Compare
Choose a tag to compare

New Features

Pest Tests Migration

This release migrates the test suite to use the Pest test framework, with support for both Pest 2 and Pest 3 (specifically for coverage annotations).

Initial Support for PHP 8.4

With the impending release of PHP 8.4, Bag can now be installed on PHP 8.4, however you must use composer update --ignore-platform-reqs as many dependencies don't yet officially support it. This is primarily to aid in testing on PHP 8.4.

Changes

  • Default fromJsonString transformer — in order to support both Laravel 10 and 11 properly it was necessary to add a default fromJsonString transformer, you can read more here

Fixes

  • Eloquent Model support now works correctly on Laravel 10
  • You can now pass in Bag objects directly when creating a collection instead of just an array of bag values
  • Faker can now be used in Factories outside of Laravel

Full Changelog: 1.1.0...1.2.0