Skip to content

errors.blade.php may fail if there is no errors array #6

@ghost

Description

I discovered that when there is only one error in error array, then error.blade.php code may fail to run.
Suggestion to improve the code is added below:

@if (isset($errors))
    @if(is_array($errors))
        @if( count($errors) > 0)
            <div class="alert alert-dismissable alert-danger fade show">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                @foreach($errors->all() as $error)
                    <li class="list-unstyled"><strong>{!! $error !!}</strong></li>
                @endforeach
            </div>
        @endif
    @else
        <div class="alert alert-dismissable alert-danger fade show">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            <li class="list-unstyled"><strong>{{$errors}}</strong></li>
        </div>
    @endif
@endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions