Download the PHP package surazdott/laravel-repository without Composer
On this page you can find all versions of the php package surazdott/laravel-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download surazdott/laravel-repository
More information about surazdott/laravel-repository
Files in surazdott/laravel-repository
Package laravel-repository
Short Description Laravel repository design pattern with service and interface.
License MIT
Informations about the package laravel-repository
Laravel Repository Design Pattern
Introduction
Laravel Repository Design Pattern package provides an overview of the design pattern used in a Laravel service and repository structure. The primary goal of this pattern is to separate concerns, improve code organization, and enhance maintainability.
Repository Pattern Components
-
Service Layer: This layer contains the business logic of your application. It abstracts the application's functionality from the controller, promoting better separation of concerns.
- Repository Layer: The repository acts as an interface to interact with the database. It abstracts the database operations from the service layer, making it easy to switch to a different data source without affecting the business logic.
Get Started
Requires PHP 8.1+
First, install package via the Composer package manager:
Generating Classes
You can also generate repository class indivisually or can be generated with options.
Basic Commands
To find help and options
Basic usages
As the software development industry continues to evolve, there has been a focus on improving code maintainability, leading to modifications in design patterns.
Base Class
use SurazDott\Repositories\BaseRepository;
use SurazDott\Services\BaseService;
Let's look at a simple example:
Repository Interface
Make your initial repository interface first.
App\Repositories\Interfaces\UserRepositoryInterface.php
Repository Class
Use this command to create your first repository class.
App\Repositories\UserRepository.php
Service Class
Use the following command to create the service class after the interface and repository.
App\Service\UserService.php
Controller Class
Now create a Laravel controller file and use the service class as below.
App\Http\Controllers\UserController.php
Eloquent Query Builder
If you want to run eloquent queries, you can call the query()
function to get an eloquent builder. Example: $this->users->query()->latest()->get();
Methods
Take a look at some of the methods in the following list.
create()
To insert a new record into the database, you should use create
method.
find()
To get the first record from database records, you should use find
method.
first()
To get the first record from database records, you should use first
method.
findOrFail()
To find specific record from database records, you should use findOrFail
method.
update()
To find specific record from database records, you should use update
method.
delete()
To delete records from database, you should use delete
method and pass integer, array or string.
query()
You can build the database builder by using the query
method and run eloquent queries and model scopes.
Contributing
If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request. Contributions are welcome!
License
This package is open-sourced software licensed under the MIT license.