Download the PHP package ttpn18121996/simple-repository without Composer

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

Simple Repository

PHP v8.2

Laravel v11.x

Installation

Install using composer:

Next, publish SimpleRepository's resources using the simple-repository:install command:

Create repository

Default Repository uses Eloquent, Run command make app/Repositories/Eloquent/UserRepository.php file and interface app/Repositories/Contracts/UserRepository.php

You can specify a model that your repository depends on during creation by adding options --model or -m.

Use another repository during build by adding the --repo or -r option. For example, if you want to use Redis instead of Eloquent, now the repository will be created in the path app/Repositories/Redis/UserRepository.php

After creating the repository remember to declare in app/Providers/RepositoryServiceProvider.php where protected $repositories (By default they will be added automatically)

The example shows the dynamic extension of the repository pattern. We use province data in the database. After a while, we realize that using local data is no longer suitable and we want to use a data source from an external web service. Editing the existing Eloquent\ProvinceRepository content will result in errors or be difficult to revert to before. Instead, we will create a new repository called WebService\ProvinceRepository while still ensuring its accuracy like the old repository.

app/Repositories/Eloquent/ProvinceRepository.php

app/Repositories/WebService/ProvinceRepository.php

Finally, what we need to do is change the binding between the abstract and the concrete in RepositoryServiceProvider

Create service

Run command for make a service. Ex: make app/Services/UserService.php file.

You can specify the models your service depends on during creation by adding the --model or -m option.

You can use repositories instead of models. Specify the repositories your service depends on during creation by adding the --repo or -r option.

Customize the filter builder

Override the buildFilter method in the repository class to customize the buildFilter from the request.

Now you just need to call getAll or getPagination, the query will filter itself according to the filters you pass in.

Customize the relationship builder

Similar to the filter builder, you can override the buildRelationships method to customize relational query handling.

Customize the query builder

If you want to customize the query without affecting other methods that are using buildRelationships and buildFilter, you can override the getBuilder method.

Set an authenticated user for the service

Use authenticated users to use permission checks in the service.

Implementation and expansion

The simple repository provides two trait classes "HasFilter" and "Safetyable" that serve to build queries that handle sorting and filtering of data (HasFilter) and use transactions for data interaction (Safetyable). By default, the base service and base repository classes extend these two trait classes.

HasFilter provides a buildFilter method. To use this feature, we need to pass the filters parameter in the format:

To fix the problem of 2 tables having the same field name or you want to change the field on the url to avoid revealing the table and field names in the database, the solution is to create a "transferredFields" property in your service class.

For example: users and roles tables both have a field of "name".

Or you can also directly override the "getTransferredField" method to transfer the field name.

ModelFactory attribute

When using model in service, it will look like this:

Instead of when using a service, dependent models will be initialized and injected automatically through the container service. Now, only when you call them are they initialized and stored. You can declare and use the model in the service through the ModelFactory attribute like this:

Use database processing functions safely

Instead of like this:

You can use the handleSafely() method instead. The first parameter is a callback for processing logic, the second parameter is the title of the logging. Let's say you get an exception, it will be of the form "Title: {message content}"

Services and repositories by default use the Safetyable trait. You can directly invoke the handleSafely() method within services/repositories.

Set up a log channel for the handleSafely() method to log when something goes wrong in the config/simple-repository.php file

Tips

Inside the service class, you can call other services with the same namespace without importing them and instantiating them. You can call them via the getService method with the service name as the parameter value. For example, App\Services\UserService wants to use App\Services\RoleService.


All versions of simple-repository with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-json Version *
illuminate/collections Version ^11.0
illuminate/console Version ^11.0
illuminate/contracts Version ^11.0
illuminate/database Version ^11.0
illuminate/support Version ^11.0
illuminate/log Version ^11.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 ttpn18121996/simple-repository contains the following files

Loading the files please wait ....