Download the PHP package orkhanahmadov/eloquent-repository without Composer

On this page you can find all versions of the php package orkhanahmadov/eloquent-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 eloquent-repository

Eloquent Repository for Laravel

Latest Stable Version Latest Unstable Version Total Downloads License

Build Status Test Coverage Maintainability Quality Score StyleCI

Eloquent Repository package for Laravel created with total "repository pattern" in-mind.

Requirements

Version requirement and compatibility with Laravel

Version ^3.0 - Laravel ^9.0 or higher and PHP 8.0 or higher.

Version ^2.0 - Laravel ^6.0, ^7.0 or ^8.0 or higher and PHP 7.3 or higher.

Version ^1.0 - Laravel 5.5, 5.6, 5.7, 5.8 and PHP 7.1 or higher.

Installation

You can install the package via composer:

Usage

Create a repository class and extend Orkhanahmadov\EloquentRepository\EloquentRepository abstract class.

Repository class which extends EloquentRepository must implement entity method. When using Eloquent models it's enough to return model's full namespace from the method.

Package also comes with console command that can create repository class. Pass repository class name to make:repository command to generate it.

This will create repository class inside Repositories folder in your app's autoload directory.

You can also pass Eloquent model namespace to make:repository command to automatically apply add that model to repository.

This will create UserRepository class and apply User model as entity to it.

You can use Laravel's container to inject UserRepository repository.

You can also skip creating dedicated repository class altogether, instead inject Orkhanahmadov\EloquentRepository\EloquentRepository and set Eloquent model entity dynamically.

Available methods

Eloquent Repository class offers has many familiar shortcut methods from Eloquent.

Create a model:

Creates a user with given parameters and returns created model instance.

Return all models:

Finds and returns all users with all allowed columns.

Return all models with listed columns:

Finds and returns all users with listed columns. You can skip list of columns, method will act same as all().

Paginate and return all models with given "per page" value:

Paginates all users with given "per page" value and returns paginated result.

Find a user with primary key:

Finds user with given primary key and returns model instance. If model is not available Illuminate\Database\Eloquent\ModelNotFoundException exception will be thrown.

Return all users with given "where" statement:

Returns all users where first_name is "John".

You can also pass multiple multiple "where" statements in first parameter and skip second parameter.

Returns all users where first_name is "John" and last_name is "Doe".

Return first user with given "where" statement:

Returns first user where first_name is "John".

You can also pass multiple multiple "where" statements in first parameter and skip second parameter.

Returns first user where first_name is "John" and last_name is "Doe".

Return all users with given "whereIn" statement:

Returns all users where first_name is "John", "Jane" or "Dave".

Return first user with given "whereIn" statement:

Returns first user where first_name is "John", "Jane" or "Dave".

Update a model with given properties:

Updates $user model's first_name to "Dave" and returns updated instance.

Find a model using primary key and update with given properties:

Finds a user with given primary key, updates first_name to "Dave" and returns updated instance. If model is not available Illuminate\Database\Eloquent\ModelNotFoundException exception will be thrown.

Delete a model:

Deletes $user model.

Find a model using primary key and delete:

Finds a user with given primary key and deletes. If model is not available Illuminate\Database\Eloquent\ModelNotFoundException exception will be thrown.

Find a "soft deleted" model:

Finds a "soft deleted" user with given primary key. If model is not using "soft delete" feature method will throw BadMethodCallException exception. If model is not available Illuminate\Database\Eloquent\ModelNotFoundException exception will be thrown.

Restore a "soft deleted" model:

Restores a "soft deleted" a $user model. If model is not using "soft delete" feature method will throw BadMethodCallException exception.

Find a "soft deleted" model using primary key and restore:

Finds a "soft deleted" user with given primary key and restores. If model is not using "soft delete" feature method will throw BadMethodCallException exception. If model is not available Illuminate\Database\Eloquent\ModelNotFoundException exception will be thrown.

Criteria

Package uses "criteria" for creating flexible queries. To use criteria chain withCriteria() method to repository. List of available criteria:

EagerLoad:

Use Orkhanahmadov\EloquentRepository\Repository\Eloquent\Criteria\EagerLoad to eager load relationships with query.

This will return all users with posts and country relationships eager loaded.

Scope:

Use Orkhanahmadov\EloquentRepository\Repository\Eloquent\Criteria\Scope to apply eloquent query scopes.

This will apply active and active scopes to query and return all available users.

OrderBy:

Use Orkhanahmadov\EloquentRepository\Repository\Eloquent\Criteria\OrderBy to order results with specified column and type.

This will return order users by ascending username column and return all of them.

Latest:

Use Orkhanahmadov\EloquentRepository\Repository\Eloquent\Criteria\Latest to order results with specified column and in descending order.

This will return order users by descending username column and return all of them.

You can apply multiple scopes to repository at the same time.

You can create your own criteria classes and use them with withCriteria() method. Every criteria class must implement Orkhanahmadov\EloquentRepository\Repository\Criteria\Criterion interface. This interface requires having apply($entity) method:

Caching

Repository also supports caching models. To enable caching implement Orkhanahmadov\EloquentRepository\Repository\Contracts\Cacheable interface to your repository:

Once implemented, all and find() methods will cache results. Repository will empty the cache automatically when update(), findAndUpdate(), delete() and findAndDelete() methods used.

You can implement cacheKey() method in your repository to set cache key. Default is model's table name.

You can set cache time-to-live with $cacheTTL property. By default it is set to 3600 (1 hour). Alternatively you can implement cacheTTL() method in your repository to return cache time-to-live value. Repository will ignore $cacheTTL property value when cacheTTL() method is implemented.

You can implement invalidateCache($model) method in your repository to change cache invalidation logic when update(), findAndUpdate(), delete(), findAndDelete() methods being used.

Testing

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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


All versions of eloquent-repository with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/container Version ^9.0
illuminate/console Version ^9.0
illuminate/contracts Version ^9.0
illuminate/database Version ^9.0
illuminate/support Version ^9.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 orkhanahmadov/eloquent-repository contains the following files

Loading the files please wait ....