PHP code example of xaboy / laravel-merge-request

1. Go to this page and download the library: Download xaboy/laravel-merge-request library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xaboy / laravel-merge-request example snippets


//获取验证码
Route::get('captcha', 'AuthController@captcha');
 
//登录并返回用户id
//例: [user_id=>1]
Route::post('login','AuthController@login'); 

//根据用户id获取用户信息
Route::get('user/info/{id}','AuthController@userInfo'); 

use Xaboy\MergeRequest\MergeRequest;

$mergeRequest = new MergeRequest([
    'loginInfo'=>'auth/loginInfo',
    'login'=>[
        'path'=>'login',
        'method'=>'post',
        'post'=>[
            'username'=>'username',
            'password'=>'password',
        ]
    
    ],
    'userInfo'=>[
        'path'=>'user/info/{id}',
        'route'=>[
            'id'=>'${mr:login.user_id}' //模板变量
        ]
    ]
])

$mergeData = $mergeRequest->run();

class Observer{
    public function executing($key, $mergeData){}
    public function executed($res, $key, $mergeData){}
    public function loaded($mergeData){}
}

//绑定
$mergeRequest->observer(Observer::class);

Route::post('user/update/{id}','AuthController@updateUser')->name('user.update');

[
    'path'=>'user/update/{id}',
    'method'=>'post',
    'route'=>[
        'id'=>1
    ]
]

[
    'path'=>'AuthController@updateUser',
    'method'=>'post',
    'route'=>[
        'id'=>1
    ]
]

[
    'path'=>'user.update',
    'method'=>'post',
    'route'=>[
        'id'=>1
    ]
]

[
    'path'=>'user/update/1',
    'method'=>'post'
]