承接 coloredcow/laravel-mobile-api 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

coloredcow/laravel-mobile-api

Composer 安装命令:

composer create-project coloredcow/laravel-mobile-api

包简介

A Laravel package to setup mobile

README 文档

README

Prerequisite

This package requires a basic understanding of Laravel Passport.

Installation

  1. Add this package in your project.
  2. 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.

Handling web responses only

The first argument is the array of data you pass to the view. The second argument is the view name.

return $this->returnFormattedResponse(['projects' => $projects], 'project.index');

Handling both web and API responses

Use two closures for sending different responses for web and api.

return $this->returnFormattedResponse(
    function () {
       // api response here
    },
    
    function () {
       // web response here
    }
);

Exception Handling

For clear error responses you need to add the trait in the App\Exceptions\Handler class and add the following code snippt in report method.

public function render($request, Exception $exception)
{
    if($this->isApi()) {
        return $this->renderErrorResponseForAPI($exception);
    }
    return parent::render($request, $exception);
}
    

Auth Middleware

If you want to set the auth user for every authenticated route then add RestApiMiddleware in your project and apply in on routes.

In kernel.php

'restapi' => ColoredCow\LaravelMobileAPI\RestAPIMiddleware::class,

In routes/api.php file

Route::group(['middleware' => ['auth:api', 'restapi:auth'] ], function () {
    // routes
});

统计信息

  • 总下载量: 617
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固