PHP code example of ognjen / laravel-validatable

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

    

ognjen / laravel-validatable example snippets



namespace App;

use Illuminate\Database\Eloquent\Model;
use Ognjen\Laravel\Validatable;

class User extends Model {
    use Validatable;

    const VALIDATION_MESSAGES = ['age.numeric'=> 'Custom numeric message'];
    protected $fillable = ['name', 'email', 'age'];
    
    protected function getValidationMessages()
    {
        return self::VALIDATION_MESSAGES;
    }

    protected function getValidationRules()
    {
        return [
            'name' => '

$user = User::create([
    'name' =>'name',
    'email'=>'[email protected]',
    'age' => 66
]);

if ($user->hasValidationErrors())
{
    $user->getValidationErrors();
}  

$user = new User();
$user->name = 'name';
$user->email = '[email protected]';
$user->age = 'not a numeric';

if ($user->save() === false)
{
    $user->getValidationErrors();
}