I added proengsoft/laravel-jsvalidation to my laravel 6 app which works ok on my
ubuntu 18 with PHP 7.2.24
But My client pulling the version got error on his Windows / php 7.4.2 as :
#57 C:\xampp\htdocs\primewatch\public\index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#58 {main}
[previous exception] [object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Argument 2 passed to Proengsoft\JsValidation\JsValidatorFactory::__construct() must be of the type array, null given, called in C:\xampp\htdocs\primewatch\vendor\proengsoft\laravel-jsvalidation\src\JsValidationServiceProvider.php on line 38 at C:\xampp\htdocs\primewatch\vendor\proengsoft\laravel-jsvalidation\src\JsValidatorFactory.php:37)
[stacktrace]
#0 C:\xampp\htdocs\primewatch\vendor\proengsoft\laravel-jsvalidation\src\JsValidationServiceProvider.php(38): Proengsoft\JsValidation\JsValidatorFactory->__construct(Object(Illuminate\Foundation\Application), NULL)
#1 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\Container\Container.php(799): Proengsoft\JsValidation\JsValidationServiceProvider->Proengsoft\JsValidation\{closure}(Object(Illuminate\Foundation\Application), Array)
#2 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\Container\Container.php(681): Illuminate\Container\Container->build(Object(Closure))
#3 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(785): Illuminate\Container\Container->resolve('jsvalidator', Array, true)
#4 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\Container\Container.php(629): Illuminate\Foundation\Application->resolve('jsvalidator', Array)
#5 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(770): Illuminate\Container\Container->make('jsvalidator', Array)
#6 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\Container\Container.php(1245): Illuminate\Foundation\Application->make('jsvalidator')
#7 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(198): Illuminate\Container\Container->offsetGet('jsvalidator')
#8 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(166): Illuminate\Support\Facades\Facade::resolveFacadeInstance('jsvalidator')
#9 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(255): Illuminate\Support\Facades\Facade::getFacadeRoot()
#10 C:\xampp\htdocs\primewatch\storage\framework\views\68757a9c9b2f658eb9358cc98549740ca7f9e23d.php(34): Illuminate\Support\Facades\Facade::__callStatic('formRequest', Array)
#11 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\View\Engines\PhpEngine.php(43): include('C:\\xampp\\htdocs...')
#12 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\View\Engines\CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('C:\\xampp\\htdocs...', Array)
#13 C:\xampp\htdocs\primewatch\vendor\facade\ignition\src\Views\Engines\CompilerEngine.php(36): Illuminate\View\Engines\CompilerEngine->get('C:\\xampp\\htdocs...', Array)
#14 C:\xampp\htdocs\primewatch\vendor\laravel\framework\src\Illuminate\View\View.php(143): Facade\Ignition\Views\Engines\CompilerEngine->get('C:\\xampp\\htdocs...', Array)
I have app/Http/Requests/ShipRequest.php with :
<?php
namespace AppHttpRequests;
use IlluminateFoundationHttpFormRequest;
use IlluminateHttpRequest;
use AppHttpTraitsfuncsTrait;
use AppShip;
class ShipRequest extends FormRequest
{
use funcsTrait;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$request= Request();
return Ship::getValidationRulesArray( $request->get('id') );
}
}
And in Ship Model method getValidationRulesArray is defined as :
public static function getValidationRulesArray($ship_id= null) : array
{
$validationRulesArray = [
'title' => [
'required',
'string',
'max:255',
Rule::unique(with(new Ship)->getTable())->ignore($ship_id),
],
'company_id' => 'required|exists:' . ( with(new Company)->getTable() ).',id',
];
return $validationRulesArray;
}
I wonder why such error on Windows/php 7.4. Can it be php different issue or what ?
"laravel/framework": "^6.2",
"proengsoft/laravel-jsvalidation": "^2.5",
Thanks!
2
Answers
make sure use JsValidatorFacade not JsValidatorFactory
you can use this syntac
use ProengsoftJsValidationFacadesJsValidatorFacade as JsValidator;
Sometimes, all you need is to run following command
because validator is not loading the jsvalidation config file just created in config directory
Hope it helps somebody.