37 lines
774 B
PHP
37 lines
774 B
PHP
<?php
|
|
|
|
namespace App\Shared\Http;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
class RequestInput
|
|
{
|
|
public function __construct(private Request $request) {}
|
|
|
|
public function string(string $key): ?string
|
|
{
|
|
$value = $this->request->input($key);
|
|
if (is_string($value)) {
|
|
return $value;
|
|
}
|
|
if (is_int($value) || is_float($value) || is_bool($value)) {
|
|
return (string) $value;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function integer(string $key): ?int
|
|
{
|
|
$value = $this->request->input($key);
|
|
|
|
return is_int($value) ? $value : null;
|
|
}
|
|
|
|
public function boolean(string $key): ?bool
|
|
{
|
|
$value = $this->request->input($key);
|
|
|
|
return is_bool($value) ? $value : null;
|
|
}
|
|
}
|