PHP code example of miken32 / network-rules

1. Go to this page and download the library: Download miken32/network-rules 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/ */

    

miken32 / network-rules example snippets




namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class MyFormRequest extends FormRequest
{
    public function rules(): array
    {
        return [

          'address'      => ['in_network:192.168.10.0/24'], // must be an IPv4 address in the specified network
          'subnet'       => ['netv4'], // must be an IPv4 CIDR network
          'ipv6_subnet'  => ['netv6:48,56'], // must be an IPv6 CIDR network between 48 and 56 bits
        ];
    }
}



namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Miken32\Validation\Network\Rules;

class AnotherFormRequest extends FormRequest
{
    public function rules(): array
    {
        return [
          'address'      => [new Rules\InNetwork('192.168.10.0/24')], // must be an IPv4 address in the specified network
          'subnet'       => [new Rules\Netv4()], // must be an IPv4 CIDR network
          'ipv6_subnet'  => [new Rules\Netv6(48, 56)], // must be an IPv6 CIDR network between 48 and 56 bits
        ];
    }
}