Support the ongoing development of Laravel.io →
posted 10 years ago
Architecture
Last updated 2 years ago.
0

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 ;-)

Last updated 2 years ago.
0

Thanks, but this additional layer of abstraction consumes additional time when u're doing simple product catalogue for example.

Last updated 2 years ago.
0

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 ;-)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.