Response Macros 输出宏 是一个怎么样的概念?可以用他来干嘛

If you would like to define a custom response that you can re-use in a variety of your routes and controllers, you may use the macro method on an implementation of
官方说是可以用来代码复用 But How???I am confused
已邀请:

FiveSay - 成武

赞同来自: 安正超 JasonLaravel 宋小北 sheng9632

在 API 规范中应该会比较常用
Response::macro('success', function($data)
{
    return Response::make(array(
        'status' => true,
        'data'   => $data,
    ));
});


/*
|--------------------------------------------------------------------------
| 开发测试
|--------------------------------------------------------------------------
*/
Route::get('test', function () {

    $data = array('user' => array('name' => 'admin', 'last_ip' => '...'));
    return Response::success($data);

});

要回复问题请先登录注册