Download the PHP package elegantmedia/laravel-simple-repository without Composer

On this page you can find all versions of the php package elegantmedia/laravel-simple-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-simple-repository

Laravel Simple Repository

Latest Version on Packagist CI Status Code Coverage

A clean and type-safe implementation of the repository pattern for Laravel 12+ applications.

Version Compatibility

Package Version Laravel Version PHP Version Branch
5.x 12.x ^8.2 v5.x
4.x 11.x ^8.2 v4.x
3.x 10.x ^8.1 master
2.x 9.x ^8.0 master

Documentation

What is Laravel Simple Repository?

Laravel Simple Repository provides a powerful abstraction layer between your application logic and data persistence. It implements the repository pattern with modern PHP features, offering a clean, maintainable, and testable approach to data access.

Why Use This Package?

Repository Methods

Complete Method Reference

Method Description
Query Building
newModel() Create a new instance of the model
newQuery() Create a new query builder instance
newFilter($defaults = true) Create a new filter instance for complex queries
List/Search Operations
all($with = []) Get all models with optional relationships
paginate($perPage = 50, $with = [], $filter = null) Paginate results with optional relationships and filters
simplePaginate($perPage = 50, $with = [], $filter = null) Simple pagination without total count
search($filter = null) Search models using the provided filter
searchByTerm($term) Simple search for models by a search term
searchPaginated($term, $perPage = 50) Search models with pagination
Find Operations
find($id, $with = []) Find a model by its primary key
findByUuid($uuid, $with = []) Find a model by UUID
findByField($field, $value, $with = []) Find a model by a specific field value
findOrCreate($searchAttributes, $additionalAttributes = []) Find or create a model with given attributes
findOrCreateById($id, $attributes, $idColumn = 'id') Find or create a model by ID
findOrFail($id) Find a model by ID or throw exception
findByFieldOrFail($field, $value) Find by field or throw exception
findWithTrashed($id) Find including soft deleted records
findOnlyTrashed($id) Find from soft deleted records only
findMany($ids) Find multiple models by their primary keys
findManyByField($field, $value) Find multiple models by field value
Create Operations
create($attributes) Create a new model instance
createMany($records) Create multiple model instances
firstOrNew($attributes, $values = []) Get first matching model or instantiate new
firstOrCreate($attributes, $values = []) Get first matching model or create it
Update Operations
updateModel($model, $attributes) Update a model instance
updateById($id, $attributes, $idColumn = 'id') Update a model by ID
updateWhere($where, $data) Update models matching conditions
updateOrCreateById($id, $attributes, $idColumn = 'id') Update or create a model by ID
updateOrCreateByUuid($attributes) Update or create a model by UUID
save($model) Save a model instance
Delete Operations
delete($id) Delete a model by ID
deleteWhere($where) Delete models matching conditions
deleteManyByIds($ids) Delete multiple models by IDs
restore($id) Restore a soft deleted model
forceDelete($id) Permanently delete a model
Aggregate Methods
sum($column, $where = []) Get the sum of a column
avg($column, $where = []) Get the average of a column
min($column, $where = []) Get the minimum value of a column
max($column, $where = []) Get the maximum value of a column
count($where = []) Count models matching conditions
Utility Methods
exists($where = []) Check if models exist with conditions
value($column, $where = []) Get single column value from first result
pluck($column, $where = [], $key = null) Get array of column values
chunk($count, $callback, $where = []) Process results in chunks
random($count = 1) Get random model(s)
Transaction Methods
withTransaction($enabled = true) Enable/disable automatic transaction wrapping
transaction($callback) Execute callback within a transaction
beginTransaction() Start a new database transaction
commit() Commit the active transaction
rollback() Rollback the active transaction
transactionLevel() Get number of active transactions
Model Information
getModelClass() Get the fully qualified class name
getModel() Get the model instance

Filter Methods

The SearchFilter class provides powerful query building capabilities through composition. These methods can be chained to build complex queries.

Laravel Query Builder Methods

Important: The SearchFilter class automatically inherits ALL Laravel query builder methods through composition. This means you can use any Eloquent query builder method like where(), whereIn(), whereNull(), whereBetween(), whereHas(), orderBy(), with(), select(), join(), groupBy(), and many more without us having to duplicate them in our codebase.

Repository-Specific Filter Methods

These are custom methods provided by the repository pattern that enhance the filtering experience:

Method Description
setKeyword($keyword) Set search keyword for searchable models
setSortBy($field) Set the default sort field
setSortDirection($direction) Set sort direction ('asc' or 'desc')
setPaginate($paginate = true) Enable/disable pagination
setPerPage($perPage) Set items per page (max 100)

Date Filtering Methods

These methods are available through the DateFilterableTrait and provide convenient date-based filtering:

Method Description
whereDateIs($date, $column = 'created_at') Filter where date equals the given date
whereDateTimeIs($dateTime, $column = 'created_at') Filter where datetime equals the given datetime
whereDateBefore($date, $column = 'created_at') Filter where date is before the given date
whereDateAfter($date, $column = 'created_at') Filter where date is after the given date
whereDateBetween($start, $end, $column = 'created_at') Filter where date is between two dates (inclusive)
whereDateInPeriod($period, $column = 'created_at') Filter where date is within a Carbon period
whereDateWithin($interval, $column = 'created_at') Filter within interval from now (e.g., last 7 days)
whereDateToday($column = 'created_at') Filter records created today
whereDateYesterday($column = 'created_at') Filter records created yesterday
whereDateThisWeek($column = 'created_at') Filter records created this week
whereDateLastWeek($column = 'created_at') Filter records created last week
whereDateThisMonth($column = 'created_at') Filter records created this month
whereDateLastMonth($column = 'created_at') Filter records created last month
whereDateThisYear($column = 'created_at') Filter records created this year
whereDateLastYear($column = 'created_at') Filter records created last year
whereDateLastDays($days, $column = 'created_at') Filter records created in the last N days
whereDateLastHours($hours, $column = 'created_at') Filter records created in the last N hours
whereDateLastMinutes($minutes, $column = 'created_at') Filter records created in the last N minutes

Financial Date Filtering Methods

These methods are available through the FinancialDateFilterableTrait and provide financial period filtering:

Method Description
whereDateThisQuarter($column = 'created_at') Filter records created this quarter
whereDateLastQuarter($column = 'created_at') Filter records created last quarter
whereDateInQuarter($quarter, $year = null, $column = 'created_at') Filter records in a specific quarter (1-4)
whereDateInThisFinancialYear($column = 'created_at') Filter records in current financial year (Jul-Jun)
whereDateInLastFinancialYear($column = 'created_at') Filter records in last financial year
whereDateInFinancialYear($endingYear, $column = 'created_at') Filter records in specific financial year

Usage Examples

Detailed Usage Examples

Query Building Methods

When to Use newFilter() vs newQuery()

Use newFilter() for:

Use newQuery() for:

Key Differences:

Feature newFilter() newQuery()
Purpose Search and filtering with repository pattern Direct Eloquent query builder access
Return Type FilterableInterface Eloquent\Builder
Pagination Built-in pagination control Manual pagination required
Reusability Designed for reuse One-time use
Search Features setKeyword() for model's searchable fields Manual search implementation
Method Chaining Repository-specific + Laravel methods Only Laravel query builder methods
Best For Application search features, API filters Complex SQL, performance-critical queries

Pagination Methods

Search Methods

Update Methods

Aggregate Methods

Utility Methods

Transaction Methods

Filter-Specific Methods

Date Filtering Examples

Quick Start

Installation

Configuration

Publish the configuration file to customize default settings:

This will create config/simple-repository.php where you can configure:

Example configuration:

Basic Usage

1. Create a repository:

2. Use in your controller:

3. Add search to your model:

4. Search with filters:

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-simple-repository with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/console Version ^12.0
illuminate/database Version ^12.0
illuminate/support Version ^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package elegantmedia/laravel-simple-repository contains the following files

Loading the files please wait ....