PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 28, 2022

[FIXED] Laravel update request validation not working on 9.x

 February 28, 2022     laravel, laravel-validation, request-validation, validation     No comments   

Issue

I have create a validation request file on request folder. It working fine in new insert. But when i update, it's not working also i pass the unique $id but not working.

a. Resource controller update method

public function update(KlassNameRequest $request, $id)
{
    $validated = $request->validated();
    KlassName::where('id', $id)->update($validated);
}

b. Validation code

public function rules()
{
    return [
        'name'          => 'required|unique:klass_names|max:128,' . $this->id,
        'ref'           => 'required|unique:klass_names|numeric|between:1,999,' . $this->id,
        'seat_quota'    => 'required|numeric|between:1,9999',
        'division'      => 'required',
        'semester'      => 'required',
    ];
}

This message shows me when i update

This message shows me when i update


Solution

I have solve my problem in this way -

a. Add extra input hidden field passing id for $request method. Because my route is resource group route -

<form action="{{ route('adm.kls.update', $kls->id) }}" method="post">
    @csrf
    @method('PUT')

    <input type="hidden" name="id" value="{{ $kls->id }}">
</form>

b. Some editing in validation code.

public function rules() {
  return [
    'name' => 'required|max:128|unique:klass_names,name,' . $this->id,
    'ref' => 'required|numeric|between:1,999|unique:klass_names,ref,' . $this->id,
    'seat_quota' => 'required|numeric|between:1,9999',
  ];
}

done.



Answered By - mahbubrn
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing