omatech/lars

5,509
Install
composer require omatech/lars
Latest Version:v1.0.6
PHP:^7.1|^7.2|^7.3|^7.4|^8.0
License:MIT
Last Updated:Apr 1, 2025
Links: GitHub  ·  Packagist
Maintainer: aponscat

Laravel Repository System

LARS abstract the data layer, making it easy to maintain.

Latest Version on Packagist Total Downloads

Installation

You can install the package via composer:

composer require omatech/lars

Usage

Create your own repository class extending BaseRepository class, use the model function to set the eloquent model for the repository.

class Repository extends BaseRepository
{
    public function model() : String
    {
        return Model::class;
    }
}

Now you can create your own function using query builder easily.

public function method()
{
    return $this->query()
                ->get();
}

Criterias

Create a criteria implementing the interface CriteriaInterface. With the apply function you can filter by your own criteria.

public class Criteria implements CriteriaInterface
{
    public function apply(Builder $q) : Builder
    {
        return $q->where('role', 'admin');
    }
}
Use your criteria
public function method()
{
    return $this->pushCriteria(new FooCriteria)
                ->query()
                ->get();
}
List applied criterias
public function method()
{
    return $this->getCriterias();
}
Remove an applied criteria
public function method()
{
    return $this->pushCriteria(new FooCriteria)
                ->popCriteria(new FooCriteria)
                ->query()
                ->get();
}
Remove all applied criterias
public function method()
{
    return $this->pushCriteria(new FooCriteria)
                ->pushCriteria(new BarCriteria)
                ->resetCriteria()
                ->query()
                ->get();
}
Global criterias for all methods in repository

It is possible to apply a criteria to all methods using the construct method of the repository.

public function __construct()
{
    $this->pushCriteria(new FooCriteria);
}

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 cbohollo@omatech.com instead of using the issue tracker.

Credits

License

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

Related Packages

omatech/enigma

Enigma is a ciphersweet wrapper for laravel, it gives us the possibility to sear...

1,574 0
omatech/laravel-done-jobs

Quick way to save jobs that have been created without any problem. The antithesi...

1,333 2
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

637,827,751 9,703
laravel/framework

The Laravel Framework.

589,172,971 34,950
laravel/tinker

Powerful REPL for the Laravel framework.

498,216,183 7,442

Version History

Version Released PHP Laravel License
v1.0.6 ^7.1|^7.2|^7.3|^7.4|^8.0 5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0 MIT
v1.0.5 ^7.1|^7.2|^7.3|^7.4|^8.0 5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0 MIT
v1.0.4 ^7.1|^7.2|^7.3|^7.4|^8.0 5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0 MIT
v1.0.3 ^7.1|^7.2|^7.3|^7.4|^8.0 5.8.*|^6.0|^7.0|^8.0|^9.0 MIT
v1.0.2 ^7.1|^7.2|^7.3|^7.4|^8.0 5.8.*|^6.0|^7.0|^8.0 MIT
Pre-releases (1)
Version Released PHP Laravel License
v0.0.1-alpha ^7.1 5.8.* MIT