Issues (927)

src/Http/Requests/PostRequest.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Adminetic\Website\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Str;
8
9
class PostRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     */
14
    public function authorize(): bool
15
    {
16
        return true;
17
    }
18
19
    /**
20
     * Prepare the data for validation.
21
     */
22
    protected function prepareForValidation(): void
23
    {
24
        $this->merge([
25
            'slug' => ! is_null($this->name) ? Str::slug($this->name) : null,
26
            'meta_name' => $this->post->meta_name ?? $this->meta_name ?? $this->name ?? null,
27
            'meta_description' => $this->post->meta_description ?? $this->meta_description ?? $this->excerpt ?? null,
28
            'user_id' => Auth::user()->id,
0 ignored issues
show
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
29
        ]);
30
    }
31
32
    /**
33
     * Get the validation rules that apply to the request.
34
     *
35
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
36
     */
37
    public function rules(): array
38
    {
39
        $id = $this->post->id ?? '';
40
41
        return [
42
            'slug' => 'required|max:100|unique:'.config('website.table_prefix', 'website').'_categories,slug,'.$id,
43
            'name' => 'required|max:100|unique:'.config('website.table_prefix', 'website').'_categories,name,'.$id,
44
            'excerpt' => 'nullable|max:5500',
45
            'description' => 'nullable|max:55000',
46
            'category_id' => 'nullable|exists:'.config('website.table_prefix', 'website').'_categories,id',
47
            'active' => 'sometimes|boolean',
48
            'featured' => 'sometimes|boolean',
49
            'position' => 'nullable|numeric',
50
            'icon' => 'nullable|max:255',
51
            'color' => 'nullable|max:255',
52
            'meta_name' => 'nullable|max:100',
53
            'meta_description' => 'nullable|max:255',
54
            'meta_keywords' => 'nullable|max:100',
55
            'videos' => 'nullable',
56
            'status' => 'sometimes|numeric',
57
            'type' => 'sometimes|numeric',
58
            'user_id' => 'required|exists:users,id',
59
            'approved_by' => 'nullable|exists:users,id',
60
        ];
61
    }
62
}
63