Skip to content

DisallowHasFactorySniff Why? #38

Answered by olivernybroe
sojeda asked this question in Q&A
Discussion options

You must be logged in to vote

@sojeda Sure, will gladly explain why 🙂

The reason is that factories should be used in tests. Adding HasFactory to your model is adding code which is meant for testing into your application code.

Essentially you end up having code which will never get called outside of tests in every single model.

However it can be a bit annoying having to use the longer syntax in tests. 👀

I see three possible solutions here

  • remove the check and live with the consequence
  • create a PR for Laravel to remove the need for HasFactory trait. (Maybe macro's)
  • or you can disable this check in your codebase

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sojeda
Comment options

Answer selected by sojeda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants