Download the PHP package jkbennemann/laravel-foliage without Composer

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

Laravel Foliage

This packages allows you to validate arbitrary business requirements within your application.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

What can be validated?

You can basically validate anything as long as you can make a logical expression out of it.

Examples:

Your options are basically endless

Installation

You can install the package via composer:

You can publish the config file with:

This is the contents of the published config file:

How it works

The whole concept of this package is to enable arbitrary validations of business rules.
To achieve this we will create a binary tree from your set of rules.

The resulting tree can then be validated by a given input of data.

For each rule the required data to validate against will automatically be taken from the provided payload.

Each tree node later will be expressed as an array, containing the following data.

Usage

Instantiating new rules

To create new you can either use the class provided by the package or just make use of the Facade for an easy and expressive API.

Basic instantiation

Facade usage

A sample representation of a simple and rule will look like this

Use Aliases for rule payload

If you want to use the same rule multiple times, with different options you will need to specify an alias to the rule.
A alias basically overrides the argument name for the payload to validate against.

Assuming you as an administrator want to perform an action on behalf of a user of your application.
You as the administrator have the right to do so, but the user under consideration itself has not.

Creating rule by structured tree data

Eventually you want to store the tree structure inside your database to validate against eloquent models.

In this case you model should implement the HasValidationRules trait provided by the package.
This gives you access to those rules.

Your database field should be a json field if you're using MySQL/MariaDB.

Your model now has access to

From existing array

If you have an array, already in the tree structure, you can create a node from it like so

Validating rules

To validate a created set of rules you can

Exception Handling

By default, the validator throws an exception on first occurring validation error.

If you want to change this behaviour you can instruct the validator not to raise an exception.

Container resolution

The package makes use of the Laravel container, by taking the settings from the config file config/foliage.php

Because of this you can also instantiate a validator by calling the container.

Create a new Validation Rule

If you want to create a new rule, you can run the artisan command.

This command creates a new rule within the namespace, specified inside the config file.
The content will be

Create a new Payload Class

If you want to create a payload class that can be used for a specific rule, you can run the artisan command.

This command creates a new payload within the namespace, specified inside the config file.
The content will be

You can add any arguments to the constructor you like, e.g:

Now inside of you validation rule, you can override the used payload class for this rule as follows:

To construct the rule you can now validate your business logic like this:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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


All versions of laravel-foliage with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2
illuminate/contracts Version ^10.0
spatie/laravel-data Version ^3.11
spatie/laravel-package-tools Version ^1.14.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 jkbennemann/laravel-foliage contains the following files

Loading the files please wait ....