{"id":15561123,"url":"https://github.com/vollborn/laravel-request-cast","last_synced_at":"2026-05-03T19:31:42.569Z","repository":{"id":57660490,"uuid":"523424217","full_name":"vollborn/laravel-request-cast","owner":"vollborn","description":"Allows to cast request values into their supposed types.","archived":false,"fork":false,"pushed_at":"2022-08-21T16:25:59.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-15T04:23:00.944Z","etag":null,"topics":["casting","controller","laravel","laravel-framework","mvc","requests","validation"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vollborn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-10T16:50:09.000Z","updated_at":"2023-12-31T08:44:59.000Z","dependencies_parsed_at":"2022-09-16T04:41:48.931Z","dependency_job_id":null,"html_url":"https://github.com/vollborn/laravel-request-cast","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/vollborn/laravel-request-cast","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vollborn%2Flaravel-request-cast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vollborn%2Flaravel-request-cast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vollborn%2Flaravel-request-cast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vollborn%2Flaravel-request-cast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vollborn","download_url":"https://codeload.github.com/vollborn/laravel-request-cast/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vollborn%2Flaravel-request-cast/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32582506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["casting","controller","laravel","laravel-framework","mvc","requests","validation"],"created_at":"2024-10-02T16:05:38.396Z","updated_at":"2026-05-03T19:31:42.535Z","avatar_url":"https://github.com/vollborn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Request Cast\n\nLaravel Request Cast is a small package to cast Laravels request values into their supposed types.\n \nFor example:\nIf you build an API and validate a request parameter as int, the value attached to the request object can still be a string.\nIt only validates the content, but does not change its data type.\n\nThis JSON body would resolute as a string in your controller, because it is a string in the request itself too:\n```json\n{\n    \"integer\": \"1251\"\n}\n```\n\nThis package aims to fix this inconvenience. The same request will resolute as an int in your controller, if used correctly.\n\n## Installation\n\nThis package is available at composer.\nTo install it, run:\n```\ncomposer require vollborn/laravel-request-cast\n```\n\n## Usage\n\nThere are two ways of using this package.\n\u003cbr /\u003eYou can either...\n\n1. Use it as an extended class\n2. or as a trait if you need to extend something else.\n\nBoth will work the same way, they are just different writing styles.\n\n### Using a parent class\n\nThis is Laravel's default request.\n```php\nuse Illuminate\\Foundation\\Http\\FormRequest;\n\nclass TestRequest extends FormRequest\n{\n    ...\n```\n\nOnce we change the extended class, we should be up and running!\n```php\nuse Vollborn\\LaravelRequestCast\\Classes\\CastedRequest;\n\nclass TestRequest extends CastedRequest\n{\n    ...\n```\n\n### Using a trait\n\nSimply add the \"Casts\" trait to your request.\n\u003cbr /\u003eThat should be it.\n\n```php\nuse Illuminate\\Foundation\\Http\\FormRequest;\nuse Vollborn\\LaravelRequestCast\\Traits\\Casts;\n\nclass TestRequest extends FormRequest\n{\n    use Casts;\n    ...\n```\n\n### Casting values\n\nCasting values is pretty easy. You just need to add the \"casts\" function to your request, just like the \"rules\" function:\n```php\n\u003c?php\n\nnamespace App\\Http\\Requests;\n\nuse Illuminate\\Foundation\\Http\\FormRequest;\nuse Vollborn\\LaravelRequestCast\\Traits\\Casts;\n\nclass TestRequest extends FormRequest\n{\n    use Casts;\n\n    /**\n     * @return array\n     */\n    public function casts(): array\n    {\n        return [\n            'test' =\u003e CastTypes::BOOLEAN\n        ];\n    }\n\n    ...\n}\n```\nThis request would cast the \"test\" parameter to a boolean.\n\nFollowing cast types are available:\n```php\n# Strings\nCastTypes::STRING\n\n# Booleans\nCastTypes::BOOLEAN\nCastTypes::BOOL\n\n# Integers\nCastTypes::INTEGER\nCastTypes::INT\n\n# Arrays\nCastTypes::ARRAY\n```\n\n**Please note:**\n\u003cbr /\u003eCasted values can be null. For example: If you cast to a boolean, the value can be *true*, *false* OR *null*.\n\u003cbr /\u003eThis is supposed to be like that. If the value is null, your validation / rules will check if it is valid or not.\n\n\n## Examples\n\nHere are some example requests using casts. Feel free to copy them and try it out!\n\n### Using a parent class\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Requests;\n\nuse Vollborn\\LaravelRequestCast\\Classes\\CastedRequest;\nuse Vollborn\\LaravelRequestCast\\Classes\\CastTypes;\n\nclass TestRequest extends CastedRequest\n{\n    /**\n     * Determine if the user is authorized to make this request.\n     *\n     * @return bool\n     */\n    public function authorize(): bool\n    {\n        return true;\n    }\n\n    /**\n     * @return array\n     */\n    public function casts(): array\n    {\n        return [\n            'test' =\u003e CastTypes::BOOLEAN\n        ];\n    }\n\n    /**\n     * Get the validation rules that apply to the request.\n     *\n     * @return array\u003cstring, mixed\u003e\n     */\n    public function rules(): array\n    {\n        return [\n            'test' =\u003e 'nullable|boolean'\n        ];\n    }\n}\n```\n\n### Using a trait\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Requests;\n\nuse Illuminate\\Foundation\\Http\\FormRequest;\nuse Vollborn\\LaravelRequestCast\\Classes\\CastTypes;\nuse Vollborn\\LaravelRequestCast\\Traits\\Casts;\n\nclass TestRequest extends FormRequest\n{\n    use Casts;\n\n    /**\n     * Determine if the user is authorized to make this request.\n     *\n     * @return bool\n     */\n    public function authorize(): bool\n    {\n        return true;\n    }\n\n    /**\n     * @return array\n     */\n    public function casts(): array\n    {\n        return [\n            'test' =\u003e CastTypes::BOOLEAN\n        ];\n    }\n\n    /**\n     * Get the validation rules that apply to the request.\n     *\n     * @return array\u003cstring, mixed\u003e\n     */\n    public function rules(): array\n    {\n        return [\n            'test' =\u003e 'nullable|boolean'\n        ];\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvollborn%2Flaravel-request-cast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvollborn%2Flaravel-request-cast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvollborn%2Flaravel-request-cast/lists"}