PHP code example of laragrad / eloquent-model-validation

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

    

laragrad / eloquent-model-validation example snippets



    class Test extends Model
    {
        use \Laragrad\Models\Concerns\UseValidation;
        
        protected $rules => [
            'title' => ['string', 'max:150'],
            'value' => ['integer', 'min:0', 'max:50'],
            'description' => ['string', 'nullable'],
        ];
        
        ...
    }



    use App\Models\Test;
    
    class TestController extends Controller
    {
        public function add(Request $request)
        {
            $model = \App::make(Test)
                ->tempFillable([
                    'title',
                    'value',
                    'description',
                ])
                ->fill($request->all())
                ->validate()
                ->save();
        }
    }