I\'m new to Laravel (only experienced Laravel 5, so no legacy hang up here)
I\'d like to know how to extend the core Request class. In addition to how to extend it,
I guess you will have to extend also RequestForm
. I use trait to avoid code duplication. Code below is relevant for Laravel 5.3.
app/Http/ExtendRequestTrait.php
app/Http/Request.php
app/Http/FormRequest.php
For phpunit test working you will have to override call
method to make it using right Request
class here Request::create
.
test/TestCase.php
app->make('Illuminate\Contracts\Http\Kernel');
$this->currentUri = $this->prepareUrlForRequest($uri);
$this->resetPageContext();
$request = Request::create(
$this->currentUri, $method, $parameters,
$cookies, $files,
array_replace($this->serverVariables, $server),
$content
);
$response = $kernel->handle($request);
$kernel->terminate($request, $response);
return $this->response = $response;
}
}
and don't forget to switch Illuminate\Http\Request::capture()
to App\Http\Request::capture()
in public/index.php
file and to add $app->alias('request', 'App\Http\Request');
after or inside $app = require_once __DIR__.'/../bootstrap/app.php';