Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PHP
laravel-sms
Commits
a3c1a45f
Commit
a3c1a45f
authored
4 years ago
by
康帅杰
Browse files
Options
Download
Email Patches
Plain Diff
sms验证规则增加语言包
parent
a1a1ed49
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
resources/lang/zh-CN/sms.php
+4
-1
resources/lang/zh-CN/sms.php
src/SmsServiceProvider.php
+22
-11
src/SmsServiceProvider.php
with
26 additions
and
12 deletions
+26
-12
resources/lang/zh-CN/sms.php
View file @
a3c1a45f
...
...
@@ -4,7 +4,7 @@
* @Author: kidkang
* @Date: 2021-03-02 18:14:04
* @Last Modified by: kidkang
* @Last Modified time: 2021-03-0
2 18:14:43
* @Last Modified time: 2021-03-0
3 08:57:17
*/
return
[
'code'
=>
'验证码'
,
...
...
@@ -18,4 +18,7 @@ return [
'fail'
=>
[
3002
,
'验证失败'
],
],
],
'rules'
=>
[
'sms'
=>
'验证码不正确'
,
],
];
This diff is collapsed.
Click to expand it.
src/SmsServiceProvider.php
View file @
a3c1a45f
...
...
@@ -4,7 +4,7 @@
* @Author: kidkang
* @Date: 2021-03-01 17:42:38
* @Last Modified by: kidkang
* @Last Modified time: 2021-03-0
2 18:59:17
* @Last Modified time: 2021-03-0
3 08:58:04
*/
namespace
Yjtec\Sms
;
...
...
@@ -32,19 +32,11 @@ class SmsServiceProvider extends ServiceProvider
],
'migrations'
);
//rules
Validator
::
extend
(
'sms_type'
,
function
(
$attribute
,
$value
,
$parameters
,
$validator
)
{
return
in_array
(
$value
,
config
(
'sms.types'
));
});
//resource
$this
->
loadTranslationsFrom
(
__DIR__
.
'/../resources/lang/'
,
'sms'
);
$this
->
registerRules
();
//validator
Validator
::
extend
(
'sms'
,
function
(
$attribute
,
$value
,
$parameters
,
$validator
)
{
$type
=
isset
(
$parameters
[
0
])
?
$parameters
[
0
]
:
'default'
;
$phoneField
=
isset
(
$parameters
[
1
])
?
$parameters
[
1
]
:
'phone'
;
$phone
=
$validator
->
getData
()[
$phoneField
];
return
app
(
'sms'
)
->
type
(
$type
)
->
check
(
$phone
,
$value
);
});
}
public
function
register
()
...
...
@@ -70,6 +62,25 @@ class SmsServiceProvider extends ServiceProvider
});
}
protected
function
registerRules
()
{
Validator
::
extend
(
'sms_type'
,
function
(
$attribute
,
$value
,
$parameters
,
$validator
)
{
return
in_array
(
$value
,
config
(
'sms.types'
));
});
Validator
::
extend
(
'sms'
,
function
(
$attribute
,
$value
,
$parameters
,
$validator
)
{
$type
=
isset
(
$parameters
[
0
])
?
$parameters
[
0
]
:
'default'
;
$phoneField
=
isset
(
$parameters
[
1
])
?
$parameters
[
1
]
:
'phone'
;
$phone
=
$validator
->
getData
()[
$phoneField
];
return
app
(
'sms'
)
->
type
(
$type
)
->
check
(
$phone
,
$value
);
});
Validator
::
replacer
(
'sms'
,
function
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
return
trans
(
'sms::sms.rules.sms'
);
});
}
protected
function
getMigrationFileName
(
Filesystem
$filesystem
,
$migrationFileName
):
string
{
$timestamp
=
date
(
'Y_m_d_His'
);
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help