The
request
function returns the current request instance or obtains an input field's value from the current request:<?php $request = request();
$value = request('key', $default);
<?php if ($code instanceof Response) {
throw new HttpResponseException($code);
} elseif ($code instanceof Responsable) {
throw new HttpResponseException($code->toResponse(request()));
}
app()->abort($code, $message, $headers);
<?php };
$payload = $callable(function ($default, $precognition = null) {
$response = request()->isPrecognitive()
? ($precognition ?? $default)
: $default;
<?php ? ($precognition ?? $default)
: $default;
abort(Router::toResponse(request(), value($response)));
});
if (request()->isPrecognitive()) {
<?php abort(Router::toResponse(request(), value($response)));
});
if (request()->isPrecognitive()) {
abort(204, headers: ['Precognition-Success' => 'true']);
}
<?php public function validateWith($validator, ?Request $request = null)
{
$request = $request ?: request();
if (is_array($validator)) {
$validator = $this->getValidationFactory()->make($request->all(), $validator);
<?php ->middleware(PrecognitionInvokingController::class);
$this->get('test-route');
$this->assertNull(request()->attributes->get('precognitive'));
$this->assertFalse(request()->isPrecognitive());
$this->get('test-route', ['Precognition' => 'true']);
<?php $this->get('test-route');
$this->assertNull(request()->attributes->get('precognitive'));
$this->assertFalse(request()->isPrecognitive());
$this->get('test-route', ['Precognition' => 'true']);
$this->assertTrue(request()->attributes->get('precognitive'));
<?php $this->assertFalse(request()->isPrecognitive());
$this->get('test-route', ['Precognition' => 'true']);
$this->assertTrue(request()->attributes->get('precognitive'));
$this->assertTrue(request()->isPrecognitive());
}
<?php $this->get('test-route', ['Precognition' => 'true']);
$this->assertTrue(request()->attributes->get('precognitive'));
$this->assertTrue(request()->isPrecognitive());
}
public function testItReturnsTheEmptyResponseWhenNotBailing()