Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
朱继来
/
后台订单管理
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a162353e
authored
Oct 31, 2019
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
temp
parent
7aec11d6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
app/Http/Controllers/Controller.php
app/Http/Controllers/Controller.php
View file @
a162353e
...
...
@@ -6,8 +6,88 @@ use Illuminate\Foundation\Bus\DispatchesJobs;
use
Illuminate\Routing\Controller
as
BaseController
;
use
Illuminate\Foundation\Validation\ValidatesRequests
;
use
Illuminate\Foundation\Auth\Access\AuthorizesRequests
;
use
Session
;
class
Controller
extends
BaseController
{
use
AuthorizesRequests
,
DispatchesJobs
,
ValidatesRequests
;
/**
* 防止表单重复提交的key前缀
* @var string
*/
private
$formResubmitPrefix
=
'f_'
;
/**
* 将key加个前缀
* @param unknown $key
* @return string
*/
private
function
formResubmitKeyProcess
(
$key
)
{
if
(
empty
(
$key
)){
//默认使用当前路由的uri为key
return
$this
->
formResubmitPrefix
.
Route
::
current
()
->
uri
;
}
else
{
return
$this
->
formResubmitPrefix
.
$key
;
}
}
/**
* 在初始化表单前调用(如上面分步实现中的showRegistrationForm()方法中)
* @param unknown $key
*/
protected
function
formInit
(
$key
=
null
)
{
$key
=
$this
->
formResubmitKeyProcess
(
$key
);
Session
::
put
(
$key
,
time
());
}
/**
* 在处理表单提交的方法中调用(如上面分步实现中的register()方法)
* @param string $message
* @param unknown $key
* @throws HttpException
*/
protected
function
formSubmited
(
string
$message
=
'请忽重复提交!'
,
$key
=
null
)
{
$key
=
$this
->
formResubmitKeyProcess
(
$key
);
if
(
Session
::
has
(
$key
))
{
Session
::
forget
(
$key
);
}
else
{
throw
new
HttpException
(
403
,
$message
);
}
}
/**
* 在处理表单提交的方法中调用(如上面分步实现中的register()方 法),该方法方便自定义重复提交时的提示页面,可以在子类中if判断一下,如果发生重复提交,响应自定义的界面
* @param string $message
* @param unknown $key
*/
protected
function
formSubmitIsRepetition
(
string
$message
=
'请勿重复提交!'
,
$key
=
null
)
{
$key
=
$this
->
formResubmitKeyProcess
(
$key
);
if
(
Session
::
has
(
$key
))
{
Session
::
forget
(
$key
);
return
false
;
}
else
{
return
response
()
->
view
(
'errors.403'
,
[
'message'
=>
$message
],
403
);
}
}
/**
* 该方法用于ajax请求,返回的数据是数组
* @param string $message
* @param unknown $key
*/
protected
function
formSubmitedForAjax
(
string
$message
=
'请勿重复提交!'
,
$key
=
null
)
{
$key
=
$this
->
formResubmitKeyProcess
(
$key
);
if
(
Session
::
has
(
$key
))
{
Session
::
forget
(
$key
);
return
false
;
}
else
{
return
[
'result'
=>
'fail'
,
'message'
=>
$message
];
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment