init commit
This commit is contained in:
156
app/Interfaces/BaseRepositoryInterface.php
Normal file
156
app/Interfaces/BaseRepositoryInterface.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace App\Interfaces;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* Base Repository Interface
|
||||
*
|
||||
* Defines the contract for all repository implementations.
|
||||
* Provides a consistent API for data access operations.
|
||||
*
|
||||
* @author David Valera Melendez <david@valera-melendez.de>
|
||||
* @since February 2025
|
||||
*/
|
||||
interface BaseRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get all records
|
||||
*
|
||||
* @param array $columns
|
||||
* @return Collection
|
||||
*/
|
||||
public function all(array $columns = ['*']): Collection;
|
||||
|
||||
/**
|
||||
* Get records with pagination
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function paginate(int $perPage = 15, array $columns = ['*']): LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* Find a record by ID
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $columns
|
||||
* @return Model|null
|
||||
*/
|
||||
public function find(int $id, array $columns = ['*']): ?Model;
|
||||
|
||||
/**
|
||||
* Find a record by ID or throw an exception
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $columns
|
||||
* @return Model
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*/
|
||||
public function findOrFail(int $id, array $columns = ['*']): Model;
|
||||
|
||||
/**
|
||||
* Find records by criteria
|
||||
*
|
||||
* @param array $criteria
|
||||
* @param array $columns
|
||||
* @return Collection
|
||||
*/
|
||||
public function findBy(array $criteria, array $columns = ['*']): Collection;
|
||||
|
||||
/**
|
||||
* Find a single record by criteria
|
||||
*
|
||||
* @param array $criteria
|
||||
* @param array $columns
|
||||
* @return Model|null
|
||||
*/
|
||||
public function findOneBy(array $criteria, array $columns = ['*']): ?Model;
|
||||
|
||||
/**
|
||||
* Create a new record
|
||||
*
|
||||
* @param array $data
|
||||
* @return Model
|
||||
*/
|
||||
public function create(array $data): Model;
|
||||
|
||||
/**
|
||||
* Update an existing record
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function update(int $id, array $data): bool;
|
||||
|
||||
/**
|
||||
* Update or create a record
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return Model
|
||||
*/
|
||||
public function updateOrCreate(array $attributes, array $values = []): Model;
|
||||
|
||||
/**
|
||||
* Delete a record by ID
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(int $id): bool;
|
||||
|
||||
/**
|
||||
* Delete records by criteria
|
||||
*
|
||||
* @param array $criteria
|
||||
* @return int Number of deleted records
|
||||
*/
|
||||
public function deleteBy(array $criteria): int;
|
||||
|
||||
/**
|
||||
* Count records
|
||||
*
|
||||
* @param array $criteria
|
||||
* @return int
|
||||
*/
|
||||
public function count(array $criteria = []): int;
|
||||
|
||||
/**
|
||||
* Check if record exists
|
||||
*
|
||||
* @param array $criteria
|
||||
* @return bool
|
||||
*/
|
||||
public function exists(array $criteria): bool;
|
||||
|
||||
/**
|
||||
* Get records with relationships
|
||||
*
|
||||
* @param array $relations
|
||||
* @return BaseRepositoryInterface
|
||||
*/
|
||||
public function with(array $relations): BaseRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Order records
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $direction
|
||||
* @return BaseRepositoryInterface
|
||||
*/
|
||||
public function orderBy(string $column, string $direction = 'asc'): BaseRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Limit records
|
||||
*
|
||||
* @param int $limit
|
||||
* @return BaseRepositoryInterface
|
||||
*/
|
||||
public function limit(int $limit): BaseRepositoryInterface;
|
||||
}
|
||||
Reference in New Issue
Block a user