Commit 19589fc5 by 杨树贤

添加前后端的表单验证

parent 1a39378c
......@@ -4,6 +4,7 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\IntegralApiRequest;
use App\Http\Services\IntegralService;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
......@@ -36,14 +37,14 @@ class IntegralsApiController extends Controller
}
public function storeIntegralApi(Request $request, IntegralService $service)
public function storeIntegralApi(IntegralApiRequest $request, IntegralService $service)
{
$result = $service->storeIntegral('/integrals', $request->all());
return $result;
}
public function updateIntegralApi(Request $request, IntegralService $service)
public function updateIntegralApi(IntegralApiRequest $request, IntegralService $service)
{
$result = $service->updateIntegral('/integrals/' . $request->id, $request->all());
......
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class IntegralApiRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'daily_limit' => 'required',
'integral_amount' => 'required',
];
}
}
......@@ -12,7 +12,7 @@ layui.use('form', function () {
data: data.field,
success: function (result) {
if (result.errcode === 0) {
layer.msg('新增成功');
layer.msg('修改成功');
window.location = '/integrals/integralList';
}
}
......
......@@ -5,14 +5,16 @@
<div class="layui-form-item">
<label class="layui-form-label">红包名称</label>
<div class="layui-input-block">
<input type="text" name="name" value="{{$integral['name']}}" lay-verify="title" autocomplete="off" placeholder="请输入红包名称"
<input type="text" name="name" value="{{$integral['name']}}" lay-verify="required"
autocomplete="off" placeholder="请输入红包名称"
class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">奖励金额</label>
<div class="layui-input-block">
<input type="text" name="integral_amount" value="{{$integral['integral_amount']}}" lay-verify="title" autocomplete="off"
<input type="text" name="integral_amount" value="{{$integral['integral_amount']}}"
lay-verify="required" autocomplete="off"
placeholder="请输入奖励金额"
class="layui-input">
</div>
......@@ -21,7 +23,8 @@
<div class="layui-inline">
<label class="layui-form-label">每个用户日限</label>
<div class="layui-input-inline">
<input type="text" name="daily_limit" value="{{$integral['daily_limit']}}" autocomplete="off" class="layui-input">
<input type="text" name="daily_limit" value="{{$integral['daily_limit']}}" lay-verify="required"
autocomplete="off" class="layui-input">
</div>
</div>
</div>
......@@ -29,9 +32,10 @@
<label class="layui-form-label">配置状态</label>
<div class="layui-input-block">
@php
$check = $integral['status']?'checked':'';
$check = $integral['status']?'checked':'';
@endphp
<input type="checkbox" {{$check}} value="{{$integral['status']}}" name="status" lay-skin="switch" lay-filter="switchStatus"
<input type="checkbox" {{$check}} value="{{$integral['status']}}" name="status" lay-skin="switch"
lay-filter="switchStatus"
lay-text="使用中|已停用">
<div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch">
<em>使用中</em><i></i>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment