'tag', ]; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ "blog_title" => [ 'required', function ($attribute, $value, $fail) { // check question is unique in that table $question_exists = Blog::where('blog_title', $value)->where('tag_id', request()->input('tag_id'))->count() > 0; if ($question_exists) { $fail('The title must be unique for this tag.'); } } ], "blog_description" => 'required', "blog_image" => 'required', // "tag_id" => 'required', ]; } public function messages() { return [ 'required' => 'The :attribute field is required.', 'unique' => 'The :attribute field is unique.', ]; } public function validated() { $blogStorageName = time() . '.' . $this->blog_image->extension(); $this->blog_image->move(public_path('/uploads/blog/images'), $blogStorageName); return array_merge(parent::validated(), [ 'slug' => SlugService::createSlug(Blog::class, 'slug', $this->blog_title), 'blog_image' => $blogStorageName ]); } }