0

How to edit text "validation.unique" in laravel 8 ?

My Controller

public function customRegistration(Request $request)
{  
    
    $request->validate([
        'name'      => 'required',
        'role_id'   => 'required',
        'username'  => 'required|unique:tbl_users',
        'password'  => 'required|min:12',
        'status_id' => 'required'
    ]);
       
    $data = $request->all();
    $check = $this->create($data);

    if ($request->role_id == 2) {
        return redirect("admin-master/show_vendor")->with('success', 'Pengguna Berhasil Di Daftarkan');
    }else{
        return redirect("admin-master/show_pengawas")->with('success', 'Pengguna Berhasil Di Daftarkan');
    }
}

I've changed the message in resouce/lang/en/validation.php

'unique' => 'The :attribute has already been taken.'

why the message that appears validation.unique ? should be has already been taken.

Error Message View

@if ($message = Session::get('success'))
          <div class="alert alert-success">
           <p>{{ $message }}</p>
          </div>
          @endif        
          @if ($message = Session::get('delete'))
          <div class="alert alert-danger">
            <p>{{ $message }}</p>
          </div>
          @endif
          @if ($errors->any())
              <div class="alert alert-danger">
                <ul>
                  @foreach ($errors->all() as $error)
                    {{ $error }}
                  @endforeach
                </ul>
              </div>
            @endif

enter image description here

9
  • What's the new error message you added in resources/en/validation.php? What error message is displayed? How is the error message displayed? Commented Jan 5, 2022 at 3:11
  • I've update my question. message error displayed in alert view Commented Jan 5, 2022 at 3:31
  • How do you display the error in your blade.php file? Commented Jan 5, 2022 at 3:40
  • the message that appears be has already been taken if the username has been registered, but I don't know where this validation.unique error message comes from Commented Jan 5, 2022 at 4:01
  • the problem is your view that show the error message. so please show it to us Commented Jan 5, 2022 at 4:21

1 Answer 1

0

we are in laravel 8 now and I would suggest using FormRequest for the SOLID principle. with that said, form request has a method messages() in return you will customize the message and it is fairly simple

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.