PHP code example of jaspaul / eloquent-model-validation

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

    

jaspaul / eloquent-model-validation example snippets




use Jaspaul\EloquentModelValidation\Model;

class Foo extends Model
{
    ...
}

'Eloquent' => Jaspaul\EloquentModelValidation\Model::class,



class Foo extends Eloquent
{
    ...
}



namespace Jaspaul\EloquentModelValidation;

use Illuminate\Database\Eloquent\Model as Base;
use Jaspaul\EloquentModelValidation\Traits\Validates;
use Jaspaul\EloquentModelValidation\Contracts\Validatable;

abstract class Model extends Base implements Validatable
{
    use Validates;

    /**
     * Returns the data to validate.
     *
     * @return array
     */
    protected function getData() : array
    {
        return $this->getAttributes();
    }
}



use Jaspaul\EloquentModelValidation\Model;

class User extends Model
{
    protected function getRules() : array
    {
        return [
            'name' => '

public function store()
{
    $user = new User(Input::all());

    try {
        $user->save();
        return $user;
    } catch (\Illuminate\Validation\ValidationException $exception) {
        // You can handle exception, access the errors $exception->getErrors(),
        // or let it bubble up and let the Laravel Exception handler deal with it.

        throw $exception;
    }
}