digitalcloud/laravel-forwarder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

digitalcloud/laravel-forwarder

Composer 安装命令:

composer require digitalcloud/laravel-forwarder

包简介

Laravel package allows you to fetch data from external link and return it to a callback url

README 文档

README

Latest Stable Version Total Downloads

Laravel Forwarder.

This package allow you to forward the request from your project to another link. The forwarded request will be carry all original information.

This package is also give you the capability to get the response inside your code, and manipulate it before returning it as a final response.

Much more, you can also modify the request before sending it to the remote link as you need.

Installation

You can install the package via composer:

composer require digitalcloud/laravel-forwarder

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file:

    'providers' => [
        DigitalCloud\Forwarder\ForwarderServiceProvider::class,
    ];

After installation, you need to register the middleware "Forward" into your kernel in "routeMiddleware" array

    protected $routeMiddleware => [
            ....
            'forward' =>  \DigitalCloud\Forwarder\Http\Middleware\Forward::class
    ];

How To Use

Now you can use new function on your route file as

Route::forward(['post'], 'http://example.com', 'posts', 'PostController@index');

This route function will make a request in background to the specified domain followed by the route

For example, the above sample will forward post request to "http://example.com/posts".

Note:

If you using api.php route file, the above sample will forward to "http://example.com/api/posts"

After the request handled, the package will pass the result as "response" property in the request to the function 'PostController@index', which you can handle, update, and return result

    public function index(Request $request)
    {
        $result = $request->response;
    
        return $result;
    }

Before Request

Do you need to update the request before send?? it's very simple, just create a function on the same controller with prefix "before"

For example, if the function name on your controller is "index", you have to make another one with "beforeIndex" name and the package will take care of the remain

Note:

Note that any before function should return "Request" object so that can be passed to the remain chain.

    public function beforeIndex(Request $request)
    {
        // make your request manipulations here
        $request = $request->merge(['token' => 'token', 'secret' => 'xxx']);

        // then return the final request
        return $request;
    }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固