Attainly/backend/app/Shared/Http/RequestInput.php

30 lines
618 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;
}
}