Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
<?php

namespace Modules\Core\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

abstract class Request extends FormRequest
{

    /**
     * Validate the input.
     *
     * @param  \Illuminate\Validation\Factory $factory
     * @return \Illuminate\Validation\Validator
     */
    public function validator($factory)
    {
        return $factory->make(
            $this->sanitizeInput(),
            $this->container->call([$this, 'rules']),
            $this->messages(),
            $this->attributes()
        );
    }

    /**
     * Sanitize the input.
     *
     * @return array
     */
    protected function sanitizeInput()
    {
        if (method_exists($this, 'sanitize')) {
            return $this->container->call([$this, 'sanitize']);
        }

        return $this->all();
    }


    /**
     * Set custom messages for validator errors.
     *
     * @return array
     */
    public function messages()
    {
        $coreLang = $moduleLang = [];
        $lang = \Localization::getCurrentLocale();
        $key = strtolower($this->getModuleName()) . '::validation.custom';
        if (\Lang::has($key, $lang)) {
            $moduleLang = trans($key);
        }
        if (\Lang::has('core::validation.custom', $lang)) {
            $coreLang = trans('core::validation.custom');
        }

        $custom = array_merge($coreLang, $moduleLang);

        return $custom;
    }

    public function getModuleName()
    {
        $class = new \ReflectionClass($this);
        $temp = explode("\\", $class->getNamespaceName());
        return $temp[1];
    }

    /**
     * Set custom attributes for validator errors.
     *
     * @return array
     */
    public function attributes()
    {
        $custom = [];
        $key = strtolower($this->getModuleName()) . '::validation.attributes';
        if (\Lang::has($key)) {
            $custom = \Lang::get($key);
        }

        return $custom;
    }
}