8.6. 用户界面 - 申请退款
申请退款
接下来我们要实现的是已支付订单的退款功能。
1. 控制器
首先创建一个 ApplyRefundRequest
来校验用户提交的退款申请,要求用户提交退款理由:
$ php artisan make:request ApplyRefundRequest
退款请求只需要用户提交申请退款理由即可:
app/Http/Requests/ApplyRefundRequest.php
<?php
namespace App\Http\Requests;
class ApplyRefundRequest extends Request
{
public function rules()
{
return [
'reason' => 'required',
];
}
public function attributes()
{
return [
'reason' => '原因',
];
}
}
接下来在 OrdersController
中添加 applyRefund()
方法作为提交退款申请的接口:
app/Http/Controllers/OrdersController.php
use App\Http\Requests\ApplyRefundRequest;
.
.
.
public function app...