Answer the question
In order to leave comments, you need to log in
Laravel 5.4 update unique field?
I tried different things, nothing comes out, it returns an error that the field is already in use:
'key' => 'unique:pgsql.public.posts,key', Rule::unique('posts')->ignore($this->id),
//или
'key' => 'unique:pgsql.public.posts,key,',$this->id,
// или
'key' => 'unique:pgsql.public.posts,key,',$id,
$this->get('id')
$this->segment(2)
$this->key
'key' => [
'required',
Rule::exists('pgsql.public.posts')->where(function ($query) {
$query->where('id', Post::where('key', $this->key)->first()->id);
}),
],
// и
'key' => [
'required',
Rule::unique('pgsql.public.posts,key')->where('key', '<>', RollGame::where('key', $this->key)->first()->id),
],
// я заменял id на key, это не помогает, только ручная валидация.
// и еще вариантов 100 пробовал разных.
Answer the question
In order to leave comments, you need to log in
Your validation is kind of strange, it should be something like this:
class UserRequest extends Request
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'user_cover_address' => 'required|image|mimes:jpeg,jpg,png,gif',
'user_firstname' => 'required|min:3|max:32',
'user_lastname' => 'required|min:3|max:32',
'user_password' => 'required|min:3|max:32',
];
}
}
public function store(Request $request, SignupRequest $rules)
{
$this->validate($request, $rules->rules());
$user = new User($request->all());
$user->save();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question