In web development, data integrity and accuracy are important. Therefore, we need to be sure that we are writing code that securely stores, updates, and deletes data in our databases. In this article, we’ll take a look at what database transactions are, why they’re important, and how to get started using them in Laravel. We will also look at typical problems associated with third-party services and database transactions.
Repositories are classes or components that contain the logic needed to access data sources. Repositories provide centralized functionality for accessing data, allowing better management and separation of the infrastructure or technology used to access data from the domain model. If you’re using an object-relational mapping (ORM) like the Laravel Framework, the code you need to implement is simplified thanks to Eloquent and strong typing. This allows you to focus on the data persistence logic rather than the data access helper functions.
PHP 5 introduced us to a new error model that is still evolving today. This model allows you to throw and catch exceptions in your application - it’s a better way to handle errors than older versions of PHP. All exceptions are instances of the Exception base class, which we can extend to introduce our own custom exceptions.
The Dependency Inversion Principle (DIP) is the fifth of the five basic principles of object-oriented programming and design, formulated by Robert Martin, known as Uncle Bob.
The principle says that
High level modules should not depend on low level modules; both should depend on abstractions. Abstractions should not depend on details. Details should depend upon abstractions.
The Interface Segregation Principle (ISP) is the fourth of the five basic principles of object-oriented programming and design, formulated by Robert Martin, known as Uncle Bob.
The principle says that
Many client-specific interfaces are better than one general-purpose interface.
The Liskov Substitution Principle (LSP) is the third of the five basic principles of object-oriented programming and design, formulated by Robert Martin, known as Uncle Bob.
The principle says that
Subclasses should be substitutable for their base classes.
The Open-Closed Principle (OCP) is second of the five basic principles of object-oriented programming and design, formulated by Robert Martin, known as Uncle Bob.
The principle says that
Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification
The Single Responsibility Principle (SRP) is the one of the five basic principles of object-oriented programming and design, formulated by Robert Martin, known as Uncle Bob.
The principle says that
A class should be one, and only one, reason to change.
If you’ve ever been familiar with the Laravel framework, it’s unlikely that you haven’t heard of service containers and service providers. In fact, they are the backbone of the Laravel framework and do all the heavy lifting when you launch an instance of any Laravel application.