Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SGUserFace's avatar

print errors from array

I use * for validate array

return [
    'roles.*'  => 'required|in:' . $roles_id,
];

How can I print the errors? (What I need to write in the has? .* not work)

@if ($errors->has('roles'))
    {{ $errors->first('roles.*') }}
@endif
0 likes
7 replies
munazzil's avatar

I think you have to add something like this and check.

 @if ($message = Session::get('error'))
      <div class="alert alert-success">
       <p>{{ $message }}</p>
      </div>
  @endif
Snapey's avatar

temporarily

@if ($errors->has('roles'))
    @dd( $errors )
@endif 
SGUserFace's avatar

@SNAPEY - But the error will be like

roles.0

roles.1

I can't do

@if ($errors->has('roles.0') || $errors->has('roles.1'))

Beacuse It's can infinity

Snapey's avatar

So what do you want to show? List every error or just the first?

Did you dump it?

SGUserFace's avatar

just the first But sometimes it can be .0 and sometimes .1

Please or to participate in this conversation.