classes/Controllers/Base.php
protected function validate($data, $rules = null, $messages = [])
    {
        // A request may be passed in when using Laravel traits, like how resetting
        // passwords work.  Get the input from it
        if (is_a($data, \Illuminate\Http\Request::class)) {
            $data = $data->input();
        }

        // Get validation rules from model
        $model = null;
        if (is_a($data, BaseModel::class)) {
            $model = $data;
            $data = $model->getAttributes();
            if (empty($rules)) {
                $rules = $model::$rules;
            }
        }

        // If an AJAX update, don't require all fields to be present. Pass just the
        // keys of the input to the array_only function to filter the rules list.
        if (Request::ajax() && Request::getMethod() == 'PUT') {
            $rules = array_only($rules, array_keys(request()->input()));
        }

        // Stop if no rules
        if (empty($rules)) {
            return;
        }

        // Build the validation instance and fire the intiating event.
        if ($model) {
            (new ModelValidator)->validate($model, $rules, $messages);
        } else {
            $messages = array_merge(BkwldLibraryValidator::$messages, $messages);
            $validation = Validator::make($data, $rules, $messages);
            if ($validation->fails()) {
                throw new ValidationFail($validation);
            }
        }
    }
protected function validate($data, $rules = null, $messages = [])
    {
        // A request may be passed in when using Laravel traits, like how resetting
        // passwords work.  Get the input from it
        if (is_a($data, \Illuminate\Http\Request::class)) {
            $data = $data->input();
        }

        // Get validation rules from model
        $model = null;
        if (is_a($data, BaseModel::class)) {
            $model = $data;
            $data = $model->getAttributes();
            if (empty($rules)) {
                $rules = $model::$rules;
            }
        }

        // If an AJAX update, don't require all fields to be present. Pass just the
        // keys of the input to the array_only function to filter the rules list.
        if (Request::ajax() && Request::getMethod() == 'PUT') {
            $rules = array_only($rules, array_keys(request()->input()));
        }

        // Stop if no rules
        if (empty($rules)) {
            return;
        }

        // Build the validation instance and fire the intiating event.
        if ($model) {
            (new ModelValidator)->validate($model, $rules, $messages);
        } else {
            $messages = array_merge(BkwldLibraryValidator::$messages, $messages);
            $validation = Validator::make($data, $rules, $messages);
            if ($validation->fails()) {
                throw new ValidationFail($validation);
            }
        }
    }
protected function validate ( $ data , $ rules = null , $ messages = [ ] ) { // A request may be passed in when using Laravel traits, like how resetting // passwords work.  Get the input from it if ( is_a ( $ data , \ Illuminate \ Http \ Request :: class ) ) { $ data = $ data -> input ( ) ; } // Get validation rules from model $ model = null ; if ( is_a ( $ data , BaseModel :: class ) ) { $ model = $ data ; $ data = $ model -> getAttributes ( ) ; if ( empty ( $ rules ) ) { $ rules = $ model :: $ rules ; } } // If an AJAX update, don't require all fields to be present. Pass just the // keys of the input to the array_only function to filter the rules list. if ( Request :: ajax ( ) && Request :: getMethod ( ) == 'PUT' ) { $ rules = array_only ( $ rules , array_keys ( request ( ) -> input ( ) ) ) ; } // Stop if no rules if ( empty ( $ rules ) ) { return ; } // Build the validation instance and fire the intiating event. if ( $ model ) { ( new ModelValidator ) -> validate ( $ model , $ rules , $ messages ) ; } else { $ messages = array_merge ( BkwldLibraryValidator :: $ messages , $ messages ) ; $ validation = Validator :: make ( $ data , $ rules , $ messages ) ; if ( $ validation -> fails ( ) ) { throw new ValidationFail ( $ validation ) ; } } }
All actions validate in basically the same way.  This is shared logic for that

@param BaseModel|Request|array $data
@param array $rules A Laravel rules array. If null, will be pulled from model
@param array $messages Special error messages
@return void

@throws ValidationFail
All actions validate in basically the same way . This is shared logic for that