mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 13:42:49 +01:00
43 lines
967 B
PHP
43 lines
967 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Requests;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
use Illuminate\Support\Facades\Validator;
|
||
|
|
||
|
trait RuntimeFormRequest
|
||
|
{
|
||
|
public static function runFormRequest($value)
|
||
|
{
|
||
|
$value = self::getMockedRequestByParameters($value);
|
||
|
|
||
|
$validator = self::createFrom($value, new self());
|
||
|
|
||
|
$validator->setContainer(app());
|
||
|
|
||
|
$validator->prepareForValidation();
|
||
|
|
||
|
$validator->setValidator(Validator::make($validator->all(), $validator->rules()));
|
||
|
|
||
|
$instance = $validator->getValidatorInstance();
|
||
|
|
||
|
return $instance;
|
||
|
// if ($instance->fails()) {
|
||
|
// return $instance->errors();
|
||
|
// }
|
||
|
|
||
|
// $validator->passedValidation();
|
||
|
|
||
|
// return $validator->all();
|
||
|
}
|
||
|
|
||
|
|
||
|
protected static function getMockedRequestByParameters($paramters)
|
||
|
{
|
||
|
$mockRequest = Request::create('', 'POST');
|
||
|
|
||
|
$mockRequest->merge($paramters);
|
||
|
|
||
|
return $mockRequest;
|
||
|
}
|
||
|
}
|