Skip to content
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

[12.x] Adds AsFluentObject caster #54909

Closed
wants to merge 3 commits into from

Conversation

freebuu
Copy link

@freebuu freebuu commented Mar 5, 2025

Hello!

Idea

I would like to suggest the functionality of casting json fields into Fluent type objects. In some cases, as a model property, you want to have not just an array, but a typed object.

Usage

Like AsCollection:

Basic usage

protected $casts = [
  'some_prop' => AsFluentObject::class, //cast to basic Fluent object
];

Cast to custom Fluent object (main behavior)

/**
 * @property string $object_property
 */
class CustomFluent extends Fluent {}

protected $casts = [
  'some_prop' => AsFluentObject::class.':'. CustomFluent::class //cast to CustomFluent object
];

As function

protected function casts(): array
{
  return [
      'some_prop' => AsFluentObject::using(CustomFluent::class) //cast to CustomFluent object
  ];
}

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants