This repository has been archived by the owner on May 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathArticleRequest.php
67 lines (61 loc) · 2.09 KB
/
ArticleRequest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Douyasi\Http\Requests;
use Douyasi\Http\Requests\Request;
class ArticleRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
//return false;
return true;
}
/**
* 自定义验证规则rules
*
* @return array
*/
public function rules()
{
$rules = [
'title' => 'required|max:80',
'category_id' => 'required|exists:metas,id,type,CATEGORY',
'content' => 'required|min:20',
'is_top' => 'boolean',
'outer_link' => 'url_link',
'thumb' => 'self_url',
];
if($this->segment(3)){
$id = $this->segment(3) ? ',' . $this->segment(3) : '';
$rules = array_add($rules, 'slug', 'required|max:30|eng_alpha_dash|unique:contents,slug'.$id);
}
//slug在添加时不予展示,修改时予以展示
return $rules;
}
/**
* 自定义验证信息
*
* @return array
*/
public function messages()
{
return [
'title.required' => '请填写文章标题',
'title.max' => '文章标题过长,建议长度不要超出60',
'slug.required' => '请填写缩略名',
'slug.max' => '缩略名过长',
'slug.unique' => '已有同名缩略名',
'slug.eng_alpha_dash' => '缩略名只能数字、字母、下划线与横杠(0-9A-Za-z_-)组合',
'category_id.required' => '请选择文章分类',
'category_id.exists' => '不存在该文章分类',
'content.required' => '请填写文章正文',
'content.min' => '文章正文过短,长度不得少于20',
'is_top.boolean' => '是否置顶必须为布尔值',
'outer_link.url_link' => '外链地址不合法',
'thumb.self_url' => '缩略图地址必须在当前域名下',
];
}
}