1

I want to customize error message with removing bullet. I'm beginner in Laravel,I don't know how can I do that. I tried changing the message in resources/lang/en/validation.php but It didn't change exactly as I wanted. Then I've tried with this code but haven't changed anything. How can I do that?

My controller is:

protected function validator(array $data)
    {
        $messages = [
            'email.required'      => 'test', 
           ];

        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],$messages
        ]);
    }

    /**
     
     * @param  array  $data
     * @return \App\Models\User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }

My blade is:

@if ($errors->any())
    <div class="alert alert-danger">
         <ul>
             @foreach ($errors->all() as $error)
               <li>{{ $error }}</li>
             @endforeach
         </ul>
    </div>
@endif
reedus6749
  • 19
  • 5
  • If you want to remove the bullets, instead of using the UL and LI tags you use div or style it https://www.w3schools.com/howto/howto_css_list_without_bullets.asp – Chung Nguyễn Trần Apr 14 '21 at 01:06

3 Answers3

0
<div class="form-group">
       <label>Name <span class="text-danger">*</span></label>
       <input type="text" class="form-control @error('name') is-invalid @enderror" name="name">
        @error('name')
             <div class="invalid-feedback">{{ $message }}</div>
        @enderror
      </div>

=>you can try this manually for email and password

Switi
  • 359
  • 3
  • 6
0
@if ($message = Session::get('success'))
  <div class="alert alert-success">
    <strong>{{ $message }}</strong>
  </div>
@endif

@if (count($errors) > 0)
  <div class="alert alert-danger">
    <ul>
      @foreach ($errors->all() as $error)
        <li>{{ $error }}</li>
      @endforeach
    </ul>
  </div>
@endif
Imran
  • 4,582
  • 2
  • 18
  • 37
Switi
  • 359
  • 3
  • 6
0

Though in your question it's not clear what you mean exactly by bullet. If you mean the styling of html list then it's a html problem instead of Laravel PHP problem.

If I am right that you want to remove the html list styling then you can just use any other tag rather than list style.

Here is an example modifying a bit of your code:

@if ($errors->any())
  @foreach ($errors->all() as $error)

    <div class="alert alert-danger">
      {{ $error }}
    </div>

  @endforeach
@endif
Imran
  • 4,582
  • 2
  • 18
  • 37