{"id":37265739,"url":"https://github.com/behaminplus/bresources","last_synced_at":"2026-01-16T00:12:37.879Z","repository":{"id":44164833,"uuid":"301474959","full_name":"behaminplus/bresources","owner":"behaminplus","description":"Behamin basic and standard api response format for laravel","archived":false,"fork":false,"pushed_at":"2025-01-09T08:59:32.000Z","size":177,"stargazers_count":6,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-01-14T15:48:51.894Z","etag":null,"topics":["api","json","laravel","php","resources","response"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/behaminplus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-10-05T16:40:24.000Z","updated_at":"2025-01-09T08:54:56.000Z","dependencies_parsed_at":"2022-09-04T18:11:13.738Z","dependency_job_id":"6bd18373-fef6-4363-9709-ca7ef6275bb0","html_url":"https://github.com/behaminplus/bresources","commit_stats":{"total_commits":117,"total_committers":7,"mean_commits":"16.714285714285715","dds":"0.41025641025641024","last_synced_commit":"bd801890f931a8347967af2a75e59f4c73d338f5"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/behaminplus/bresources","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/behaminplus%2Fbresources","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/behaminplus%2Fbresources/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/behaminplus%2Fbresources/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/behaminplus%2Fbresources/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/behaminplus","download_url":"https://codeload.github.com/behaminplus/bresources/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/behaminplus%2Fbresources/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28474431,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T00:03:33.697Z","status":"ssl_error","status_checked_at":"2026-01-15T23:58:36.859Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["api","json","laravel","php","resources","response"],"created_at":"2026-01-16T00:12:37.092Z","updated_at":"2026-01-16T00:12:37.869Z","avatar_url":"https://github.com/behaminplus.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](https://poser.pugx.org/behamin/bresources/license)](//packagist.org/packages/behamin/bresources)\n[![Tests](https://github.com/omalizadeh/bresources/actions/workflows/tests.yml/badge.svg)](https://github.com/omalizadeh/bresources/actions/workflows/tests.yml)\n[![Latest Stable Version](https://poser.pugx.org/behamin/bresources/v)](//packagist.org/packages/behamin/bresources)\n[![Total Downloads](https://poser.pugx.org/behamin/bresources/downloads)](//packagist.org/packages/behamin/bresources)\n\n# Behamin Resources\n\nBehamin standard formats for api responses.\n\n## Installation\n\n```bash\ncomposer require behamin/bresources\n```\n\n## Output Format\n\nResources:\n\n```json\n{\n    \"data\": {\n        \"id\": 1,\n        \"email\": \"test@test.com\"\n    },\n    \"message\": \"message\",\n    \"error\": {\n        \"message\": \"or error message\",\n        \"errors\": null\n    }\n}\n```\n\nResourceCollection:\n\n```json\n{\n    \"data\": {\n        \"items\": [],\n        \"count\": 0,\n        \"sum\": null\n    },\n    \"message\": null,\n    \"error\": {\n        \"message\": null,\n        \"errors\": null\n    }\n}\n```\n\nOn validation error for requests (with 422 status code):\n\n```json\n{\n    \"data\": null,\n    \"message\": null,\n    \"error\": {\n        \"message\": \"first error message in message bag\",\n        \"errors\": {\n            \"password\": [\n                \"password field is required.\"\n            ]\n        }\n    }\n}\n```\n\n## Usage\n\nCreate resources and requests with artisan commands and pass data, message, error_message or count to resources like\nfollowing examples:\n\n```php\n    public function index(EmailFilter $filters)\n    {\n        list($emails, $count) = Email::filter($filters);\n        $emails = $emails-\u003eget();\n        \n        return EmailResource::collection(['data' =\u003e $emails, 'count' =\u003e $count]);\n    }\n```\n\n```php\n    public function show(Email $email)\n    {\n        return new EmailResource(['data' =\u003e $email, 'message'=\u003e 'email info.']);\n    }\n```\n\nYou can specify output fields from transformDataItem() method of resource classes.\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Resources;\n\nuse Behamin\\BResources\\Resources\\BasicResource;\n\nclass EmailResource extends BasicResource\n{\n    protected function transformDataItem($item)\n    {\n        return [\n            'id' =\u003e $item-\u003eid,\n            'email' =\u003e $item-\u003eemail,\n            'status' =\u003e $item-\u003estatus\n        ];\n    }\n}\n\n```\n\nAlso, you can use apiResponse() helper function to directly send response\n\n```php\nclass PhoneController {\n\n    public function show(Phone $phone)\n    {\n        return apiResponse()-\u003edata($phone)-\u003emessage('phone info.')-\u003estatus(200)-\u003eget();\n    }\n    \n    public function index() {\n        $phones = Phone::all();\n        \n        return apiResponse()-\u003ecollection($phones, $phones-\u003ecount())-\u003emessage('phone info.')-\u003estatus(200)-\u003eget();\n    }\n    \n    public function update(Request $request, Phone $phone) {\n        $isUpdated = $phone-\u003eupdate($request-\u003eall());\n        \n        if (!$isUpdated) {\n            return apiResponse()-\u003eerrors('phone is not updated');\n        }\n        \n        return apiResponse()-\u003edata($phone)-\u003emessage('phone is updated')-\u003eget();\n    }\n    \n    public function delete(Phone $phone)\n    {\n        $phone-\u003edelete();\n        \n        return apiResponse()-\u003emessage('phone info.')-\u003enext('https://debut.test')-\u003estatus(200)-\u003eget();\n    }\n}\n```\n\nIn above example **message** and **status** are optional, and their default value respectively are `null` and `200`.\n\n#### Resource\n\n```bash\nphp artisan make:bresource ResourceClassName\n```\n\n#### Request\n\n```bash\nphp artisan make:brequest RequestClassName\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbehaminplus%2Fbresources","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbehaminplus%2Fbresources","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbehaminplus%2Fbresources/lists"}