Skip to content

[BindPayload] Introduce to bind payload attribute#38

Merged
techmahedy merged 5 commits intodoppar:2.xfrom
rrr63:introduce-to-bind-payload-attribute
Oct 16, 2025
Merged

[BindPayload] Introduce to bind payload attribute#38
techmahedy merged 5 commits intodoppar:2.xfrom
rrr63:introduce-to-bind-payload-attribute

Conversation

@rrr63
Copy link
Member

@rrr63 rrr63 commented Oct 16, 2025

Hello,

Since we already have bindTo() function, that take an array. I think it could be a good way to make a similar way by using directly the Model class.
How it works :

#[Route('/api/home', methods: ['POST'], name:'home.store')]
public function store(
  #[BindPayload(strict: false)]
  Home $home
) {
  return Home::createFromModel($home);
}

By adding #[BindPayload(strict: false)], you can auto bind a Model directly in the controller arguments.

I also added a createFromModel that just call a ::create($model->getAttributes())

public static function createFromModel(Model $model): static
{
   return self::create($model->getAttributes());
}

@techmahedy
Copy link
Member

I think it's gonna be amazing @rrr63, after merging, please add documentation in the request page @rrr63.

@techmahedy techmahedy merged commit 0c9e314 into doppar:2.x Oct 16, 2025
11 checks passed
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