SteamIdRule validates that submitted input resolves to a
SteamId. It mirrors the
route binding: a 64-bit ID or a
/profiles/<id> URL passes, anything else fails. The URL keeps whatever follows the
ID — a sub-path, a ? query string, a # fragment — so a link copied straight out of
the address bar passes as it stands.
Using the rule
Section titled “Using the rule”use Fkrzski\LaravelSteamApiSdk\Rules\SteamIdRule;
$request->validate([ 'steam_id' => ['required', SteamIdRule::make()],]);use Fkrzski\LaravelSteamApiSdk\Rules\SteamIdRule;use Illuminate\Foundation\Http\FormRequest;
class LinkSteamAccountRequest extends FormRequest{ public function rules(): array { return [ 'steam_id' => ['required', SteamIdRule::make()], ]; }}The rule validates, it does not transform. Build the value object yourself, or let
the AsSteamId cast do it on persist:
use Fkrzski\SteamApiSdk\ValueObjects\SteamId;
$steamId = SteamId::tryFromInput($request->string('steam_id')->value());Strict mode
Section titled “Strict mode”strict() accepts a raw 64-bit ID only — for an API endpoint documenting an exact
format, rather than a field a person types into:
'steam_id' => ['required', SteamIdRule::make()->strict()],| Input | Default | strict() |
|---|---|---|
76561198000000000 |
passes | passes |
https://steamcommunity.com/profiles/76561198000000000 |
passes | fails |
https://steamcommunity.com/profiles/76561198000000000/games?tab=all |
passes | fails |
https://steamcommunity.com/id/gabelogannewell |
fails | fails |
not-a-steam-id |
fails | fails |
A vanity URL never passes: resolving one needs an API call the rule deliberately
does not make. Accepting vanity names? Run
Steam::users()->resolveVanityUrl()
after validation.
Accepted types
Section titled “Accepted types”Besides strings the rule takes an int (a JSON body sends the ID as one) and any
Stringable, including a SteamId. Surrounding whitespace is trimmed. Every other
type — null, arrays, floats, plain objects — fails.
Error messages
Section titled “Error messages”The messages ship as a package translation:
php artisan vendor:publish --tag=steam-api-translationsPublished files:
Directorylang
Directoryvendor
Directorysteam-api
Directoryen
- validation.php the two message keys, yours to reword
- … add a locale directory beside en
return [ 'steam_id' => 'The :attribute field must be a valid Steam ID or profile URL.', 'steam_id_strict' => 'The :attribute field must be a valid 64-bit Steam ID.',];For a one-off override, pass a message the usual Laravel way instead:
$request->validate( ['steam_id' => ['required', SteamIdRule::make()]], ['steam_id' => 'Paste your Steam profile link.'],);