Repository navigation
Expand file tree
/
Copy pathStoreBlogRequest.php
More file actions
55 lines (44 loc) · 1.64 KB
/
Copy pathStoreBlogRequest.php
File metadata and controls
55 lines (44 loc) · 1.64 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
<?php
namespace App\Http\Requests\Blog;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
class StoreBlogRequest 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->title,
'meta_description' => $excerpt,
]);
}
public function rules(): array
{
return [
'title' => ['required', 'string', 'min:3', 'max:255', 'unique:blogs,title'],
'slug' => ['nullable', 'string', 'max:255', 'unique:blogs,slug'],
'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'],
];
}
}