1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Http/Requests/RuntimeFormRequest.php

36 lines
792 B
PHP
Raw Normal View History

2022-02-15 22:50:28 +01:00
<?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;
}
protected static function getMockedRequestByParameters($paramters)
{
$mockRequest = Request::create('', 'POST');
$mockRequest->merge($paramters);
return $mockRequest;
}
}