{"id":23858974,"url":"https://github.com/coloredcow/laravel-mobile-api","last_synced_at":"2025-09-08T06:31:10.313Z","repository":{"id":56956678,"uuid":"154494071","full_name":"ColoredCow/laravel-mobile-api","owner":"ColoredCow","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-16T10:19:00.000Z","size":21,"stargazers_count":1,"open_issues_count":5,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-06T17:22:24.980Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ColoredCow.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-24T12:06:01.000Z","updated_at":"2025-02-16T10:19:03.000Z","dependencies_parsed_at":"2025-01-03T03:31:24.695Z","dependency_job_id":"7b005064-3bbb-4f7d-90a3-33c90b497636","html_url":"https://github.com/ColoredCow/laravel-mobile-api","commit_stats":{"total_commits":22,"total_committers":3,"mean_commits":7.333333333333333,"dds":0.4545454545454546,"last_synced_commit":"23af655dc3656515b18c4697674f6ccf93e3183f"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ColoredCow/laravel-mobile-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColoredCow%2Flaravel-mobile-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColoredCow%2Flaravel-mobile-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColoredCow%2Flaravel-mobile-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColoredCow%2Flaravel-mobile-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ColoredCow","download_url":"https://codeload.github.com/ColoredCow/laravel-mobile-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColoredCow%2Flaravel-mobile-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274145949,"owners_count":25230114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-01-03T03:28:57.988Z","updated_at":"2025-09-08T06:31:10.004Z","avatar_url":"https://github.com/ColoredCow.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Mobile API\n\n# Prerequisite\n\nThis package requires a basic understanding of [Laravel Passport](https://laravel.com/docs/5.6/passport).\n\n\n## Installation\n\n1. Add this package in your project. \n2. Now add the trait `CanHaveAPIEndPoints` in the controller that will contribute in the mobile service. You can also add this trait in the base controller and use it. Now you can use **returnFormattedResponse** method to send the respose. This function will check the request and send the reponse accordingly.\n\n#### Handling web responses only\nThe first argument is the array of data you pass to the view. The second argument is the view name.\n```php\nreturn $this-\u003ereturnFormattedResponse(['projects' =\u003e $projects], 'project.index');\n```\n\n#### Handling both web and API responses\nUse two closures for sending different responses for web and api.\n\n```php\nreturn $this-\u003ereturnFormattedResponse(\n    function () {\n       // api response here\n    },\n    \n    function () {\n       // web response here\n    }\n);\n```\n\n## Exception Handling \n\nFor clear error responses you need to add the trait in the **App\\Exceptions\\Handler** class and add the following code snippt in report method. \n\n```php\npublic function render($request, Exception $exception)\n{\n    if($this-\u003eisApi()) {\n        return $this-\u003erenderErrorResponseForAPI($exception);\n    }\n    return parent::render($request, $exception);\n}\n    \n```\n\n\n## Auth Middleware\n\nIf you want to set the auth user for every authenticated route then add `RestApiMiddleware` in your project and apply in on routes. \n\nIn kernel.php\n```php\n'restapi' =\u003e ColoredCow\\LaravelMobileAPI\\RestAPIMiddleware::class,\n```\n\nIn routes/api.php file\n```php\nRoute::group(['middleware' =\u003e ['auth:api', 'restapi:auth'] ], function () {\n    // routes\n});\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoloredcow%2Flaravel-mobile-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoloredcow%2Flaravel-mobile-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoloredcow%2Flaravel-mobile-api/lists"}