0

why evertime I the load the page isset does not load properly its still show to the page an array like this [] ?

Views

@if(isset($errors))
{{$errors}}
@endif

Controller

 $data = Input::all();

if($errors = $this->deliveryReport->isInvalid($data))
{
    return Redirect::back()->withInput()->withErrors($errors);
}

2 Answers 2

3

This is the most common use of a collection presentation:

@if($collection->isEmpty())
    <h2>No items were found</h2>
@else
    <h2>The following {{$collection->count()}} items were found</h2>
    @foreach($collection as $c)
        {{ $c->someAttribute }}
    @endforeach
@endif

Now specifically for $errors:

@if($errors->any())
    <div id="error-box">
        @foreach ($errors->all() as $error)
            <div>{{ $error }}</div>
        @endforeach
    </div>
@endif

Remember to pass correctly $errors to your view after the validation has done its job. So in your controller:

$rules = [...];

$v = Validator::make(Input::all(), $rules);

if($v->fails())
{
    return Redirect::back()->withInput()->withErrors($v);
}

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

Comments

1

withError() make it instance of MessageBag, you can use methods on it:

@foreach($errors->all() as $error)
    {{ $error }}
@endforeach

or see the docs

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.