PHP code example of decodelabs / lucid

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

    

decodelabs / lucid example snippets


use DecodeLabs\Lucid;
$lucid = new Lucid();

// This ensures the value is a string
$myString = $lucid->cast('This is a string', 'string');

// This is nullable
$notAString = $lucid->cast(null, '?string');

// These are constraints - throws an exception
$myString = $lucid->cast('My very long piece of text', 'string', [
    'maxLength' => 10,
    'maxWords' => 4
]);

// Creates an instance of Carbon (DateTime)
$myDate = $lucid->cast('tomorrow', 'date', [
    'min' => 'yesterday',
    'max' => '+3 days'
]);

$result = $lucid->validate('potato', 'int', [
    'min' => 4
]);

if(!$result->isValid()) {
    // Do something with the potato

    foreach($result->getErrors() as $error) {
        echo $error->getMessage();
    }
}

if(!$lucid->is('not a number', 'float')) {
    // do something
}