public function rules()
{
return [
'pagetitle' => 'required|string|min:5|max:255|unique:categories,pagetitle',
'alias' => 'required|string|min:2|max:255|unique:categories,alias',
];
}
protected function prepareForValidation()
{
if($this->alias == null)
{
$this->merge([
'alias' => Str::slug($this->pagetitle),
]);
}
else
{
$this->merge([
'alias' => Str::slug($this->alias),
]);
}
}
public function withValidator($validator)
{
$validator->after(function ($validator) {
request()->merge([
'alias' => $this->request->get('alias')
]);
// $validator->errors()->add('alias', 'Something is wrong with this field!');
});
}