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

Add support for factory states [enhancement] #452

Closed
hubertnnn opened this issue Jan 23, 2019 · 5 comments
Closed

Add support for factory states [enhancement] #452

hubertnnn opened this issue Jan 23, 2019 · 5 comments
Labels
next Relevant for the next major release

Comments

@hubertnnn
Copy link

Currently if you use @transformerModel MyModel tag it will create an instance of model using
factory(MyModel::class, 1)

This works for most cases, but sometimes we have an endpoint that returns only specific type of models (eg. only admin users or only active products).

Using a different item as example makes no sense, and might even be confusing
(I had an endpoint that only returns one type of banners that had an extra field, but example was missing this field when incorrect type of banner was returned)

My suggestion is to add optional parameters to @transformerModel tag that will work as states.
So eg. @transformerModel User admin with_example_password will use following factory instead factory(User::class, 1)->states(['admin', 'with_example_password'])

@shalvah
Copy link
Contributor

shalvah commented Jan 25, 2019

I'd accept PRs for this, but I'd rather go with @transformerModel User states=admin,with_example_password instead.

lucacri pushed a commit to lucacri/laravel-apidoc-generator that referenced this issue Feb 4, 2020
@lucacri
Copy link
Contributor

lucacri commented Feb 4, 2020

I created a MR quest for this! Please let me know if it can be merged

@ncatanchin
Copy link
Contributor

Will this also be made available to the @apiResourceModel ?

@lucacri
Copy link
Contributor

lucacri commented Feb 14, 2020

My MR is only for the @apiResourceModel (at least that's why I made it)

@shalvah shalvah added next Relevant for the next major release and removed enhancement labels May 2, 2020
@shalvah
Copy link
Contributor

shalvah commented May 7, 2020

This is now supported in Scribe 🙂.

@shalvah shalvah closed this as completed May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next Relevant for the next major release
Projects
None yet
Development

No branches or pull requests

4 participants