Download the PHP package safiullahsarhandi/laravel-repository without Composer

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

This Package is used to implement repository pattern in laravel with very minimal code. Idea behind this implementation is to allow modular approach and reusable every single entity in your project and enhance your coding experience with features like model binding, repository generator, repository events etc.

Installation

using below mentioned command you can add this package in your laravel project

composer require safiullahsarhandi/laravel-repository

after installing this package you need to register provider LaravelRepository\Providers\RepositoryServiceProvider::class, in your project's config/app.php

publish assets

  1. php artisan vendor:publish --tag=repository-config this command will create repository.php configuration file in config directory which will store information like this this.

Usage

This package offers few commands which helps to perform different tasks or you can say that it's required to use this.

  1. How to Create Repository

    command: php artisan make:repository <path/to/repository> <model>

    creating repository would be easy by using this package. it register your repository in config file. and create set of files in app\Repositories directory, for instance php artisan make:repository User/UserRepository User will update your app\Repositories folder like this

    repository-dir

    and update your config file like this

  2. Create Query Filter

    idea behind filter is to extend database query. When calling any specific repository, every repository function which you will see below has some how similar structure and contain minimum amount of code. i will explain implementation for filters in next section of documentation so that you will get familier with it but for now let's check how to generate query filters with given command.

    command: php artisan make:filter <path/to/filter>

    eg: php artisan make:filter Api/UserFilter this will generate filter in app/Filters/Api/UserFilters.php

    filter-dir

    this will be final output for make:filter command.

    Make Model Filterable

    before going through that how to use UserFilter::class with any repository, we should know that what basic steps to be followed before binding filter with repository. we have to use LaravelRepository\Traits\Filterable in model to make any model filtered on demand.

    How to use Query Filter

    filter class should have methods with same name which you haved registered in protected $filters property. whenever you bind query filter with repository it reads laravel Illuminate\Support\Request instance and verify the availablity of parameters in http request. you can use it this way

    Extend Query Filter

    sometimes you want to extend filters under the hood, and don't want to expose every parameter when any specific route called. you can extend filter programitically unless filter is passed to repository.

    and your UserFilter::class should be like this

    1. Create Repository Events

      you can't override the predefined functions which repository offers, but sometimes or you can say most of the time you need to filter or performing any specific operation on particular time while execution. Using direct repository functions cannot acheive it because they are just interacting with data but do not implement your business logic. To acheive this you can bind repository event with it. you can assume that events are similar to laravel observers. whereas observers are just triggered for model but here repository event could be available for repository only

      command: php artisan make:repository-event <path/to/repository-event>

      eg: php artisan make:repository-event User/UserRepositoryEvent will create event class in app/Events/User/UserRepositoryEvent.php with following code snippet in it by default.

      how to use event

      repository events are called when you bind event class with any repository. you can see all repository methods listed below. lets say we want to create `Order and store products in database which user has selected. how it would be possible? you can create your own method and call it but we would recommend events;

      now we want to store products in our database which are associated to an order. as we have called create method so we can put some logics in beforeCreate or created in App\Events\Order\OrderRepositoryEvent::class.

      Repository Methods:

      # SR No. Method Name access modifier Events Description
      01 setModel(Model $model) public N/A sets or bind model with repository. by default model is injected but sometimes you need to set Model implicitly. so that it can work in such scenario.
      02 withCount(array $relations = []) public N/A you can pass laravel relations using this method to perform aggregation.
      03 with(array $relations = []) public N/A you can pass laravel relations using this method to perform eager loading.
      04 findAll(Filters\|null $filter = null) public beforeFetch, fetched fetches all records of injected model and can take Filter instance as parameter
      05 findById(int $id, Filters\|null $filter = null) public beforeFetch, fetched fetches specific record of injected model
      06 findOne(Filters\|null $filter = null) public beforeFetch, fetched used to fetch first user of injected model
      07 paginate(int $perPage = 10, Filters\|null $filter = null) public beforeFetch, fetched fetches all records and returns as paginated
      08 create(array $params) public beforeCreate, created create new record in model. take parameters set all columns which are fillable
      09 update(int $id, array $params, Filters\|null $filter = null) public beforeUpdate, updated update record in model
      10 delete(int $id, Filters\|null $filter = null) public beforeDelete, deleted delete record in model matched to id
      11 getTotal(Filters\|null $filter = null) public beforeFetch returns total no of records in model
      12 notification() public N/A returns LaravelRepository\Repositories\NotificationRepository::class instance .
      13 event(string $eventNamespace) public N/A bind event class with any repository.

All versions of laravel-repository with dependencies

PHP Build Version
Package Version
Requires php Version ^8.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 safiullahsarhandi/laravel-repository contains the following files

Loading the files please wait ....