PHP code example of etelford / laravel-api-validation

1. Go to this page and download the library: Download etelford/laravel-api-validation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

etelford / laravel-api-validation example snippets


use Etelford\LaravelValidation\HandlesApiRequests;



namespace App\Validation\User;

class Store extends \Etelford\LaravelValidation\BaseValidator
{
    public function rules() : array
    {
        return ['email' => '

// UserController.php
public function store($request, $id)
{
    $this->validate($request, 'User::Store');
}

$validator = $this->validate($request, 'User::Store', $throwOnFailure = false);

class VerifyMinimum extends \Etelford\LaravelValidation\CustomRule
{
    public function passes() : bool
    {
        return $this->amount >= $this->minimum;
    }

    public function messageBag() : array
    {
        return ['amount' => 'Amount must be at least' . $this->minimum];
    }
}

$customRule = new VerifyMinimum(['amount' => 100000, 'minimum' => 50000]);
$validation = $class->validate($request, 'entity::bar')->attachRules($customRule);