One of the things about writing these tips each day is that my mind has started to think in terms of "tips" any time I solve a problem or help someone else.
So I'm going to keep going on the thread regarding the uniqueness in factories and extract one more tip from that story.
This time I want to talk about effective use of documentation.
One interesting thing to note about our uniqueness solution with factories is that you would be hard-pressed to find it in the Laravel docs.
If you search on "unique" in the Laravel docs, you would find zero results that lead to the factories section.
And if you read the factories section completely, the only mention you'd see is a code sample that uses unique()
.
But we have to keep in mind that while Laravel provides the way to create factories, it pulls in the Faker library to generate the data. So we're leaving ourselves a huge blind spot if we don't also check Faker's own docs.
There are other examples of this: PHPUnit, Mockery, Carbon, and so on.
Sometimes the lines are blurred, like PHPUnit, where Laravel provides quite a few helpers on top of what PHPUnit offers, so we may have to check both places to get a feel for what is from PHPUnit and what is from Laravel.
My main point is that as good as Laravel's docs are (and they are great!), don't overlook the underlying libraries and use their docs as well.
Here to help,
Joel
P.S. Maybe you feel like you're slammed on a deadline and don't have time to mine docs to find an answer. I get it, and we can help.