Repository navigation
Expand file tree
/
Copy pathUpdateBlogRequest.php
More file actions
98 lines (82 loc) · 2.33 KB
/
Copy pathUpdateBlogRequest.php
File metadata and controls
98 lines (82 loc) · 2.33 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace App\Http\Requests\Blog;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
class UpdateBlogRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
protected function prepareForValidation(): void
{
$content = (string) $this->input('content', '');
$clean = preg_replace('/```[\s\S]*?```|\$\$[\s\S]*?\$\$/', ' [Equation] ', $content);
$clean = preg_replace('/\\$[^$\n]+\\$/', ' [Equation] ', (string) $clean);
$excerpt = Str::limit(trim(preg_replace('/\s+/', ' ', strip_tags((string) $clean))), 150);
$this->merge([
'slug' => Str::slug($this->input('title')),
'excerpt' => $excerpt,
'meta_title' => $this->input('title'),
'meta_description' => $excerpt,
]);
}
public function rules(): array
{
$blog = $this->route('blog');
return [
'title' => [
'required',
'string',
'min:3',
'max:255',
Rule::unique('blogs', 'title')->ignore($blog->id),
],
'slug' => [
'nullable',
'string',
'max:255',
Rule::unique('blogs', 'slug')->ignore($blog->id),
],
'excerpt' => [
'nullable',
'string',
'max:160',
],
'content' => [
'required',
'string',
],
'featured_image' => [
'nullable',
'image',
'mimes:jpg,jpeg,png,webp',
'max:5120',
],
'is_published' => [
'required',
'boolean',
],
'is_featured' => [
'required',
'boolean',
],
'seo_tags' => [
'nullable',
'string',
'max:255',
],
'meta_title' => [
'nullable',
'string',
'max:255',
],
'meta_description' => [
'nullable',
'string',
'max:160',
],
];
}
}