Technically no. However if you wish to test your code it makes it very easy to pass a mocked (fake) object into a class to emulate what the database would return.
I suggest you watch Jeffrey Way's Laracast on the subject: https://laracasts.com/lessons/repositories-simplified
Since watching that screencast I use the repository pattern whenever I'm using a database or external service ;-)
Thanks, but this additional layer of abstraction consumes additional time when u're doing simple product catalogue for example.
That's what I thought, but I soon found that the time spent meant that I could quickly verify that I wasn't breaking my code when I made changes later on. You may remember what you were thinking yesterday, but 3 months from now?
Test Driven Development seems a waste of time at the start, but you only need one bug that takes 2 hours to solve and you realise it would have been better to have spent on building the tests and 5 minutes to fix the bug ;-)
I've also caught bugs during coding when my tests show that my functions don't do what I intended.
Feel free not to, but there's a reason why it has become so popular ;-)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community