0

with I manage to print in the index view of the delivery notes directory what was sent by the controller, something was wrong when sending the return.

Return Controller

 return view('albaranes/index',['errors','NOOOOO']);

Data collection on the blade

@if ($errors->any())

<div class="alert alert-danger">
    <ul>
        @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
        @endforeach
    </ul>
</div>

@endif

3 Answers 3

1

try withErrors()

you need to retrun back with error

return Redirect::back()->withErrors(['errors' => 'NOOOOO']);

or if you want to pass in as data then

return view('albaranes/index')->with(['errors','NOOOOO']);

in blade

@if ($errors)

<div class="alert alert-danger">
    <ul>
      {{ $errors }} // as it is not array as u mention 
    </ul>
</div>

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

Comments

0

You should try this maybe it will be helpful for you

$errors = ['You do not have sufficient permissions to access this page.'];

return view('albaranes/index',compact('errors'));

then in blade file

@if (count($errors))

<div class="alert alert-danger">
    <ul>
        @foreach ($errors as $error)
            <li>{{ $error }}</li>
        @endforeach
    </ul>
</div>

@endif

Comments

0

I think the problem is that you are setting the array wrongly, try this way:

return view('albaranes/index',['errors' =>'NOOOOO']);

even like this, $errors will be a string, not an array, you could try:

return view('albaranes/index',['errors'=>['error1', 'error2']]);

You'll have to replace the any() and all() methods for methods for arrays , like this:

@if (count($errors)>0)

<div class="alert alert-danger">
    <ul>
        @foreach ($errors as $error)
            <li>{{ $error }}</li>
        @endforeach
    </ul>
</div>

@endif

and that should do it, I tried and it prints the list.

4 Comments

When using your code in controller the error that I get is the following: Call to a member function any() on array
It still does not work, but may it be that being already on the index view delivery albaranes it does not work well?
the thing is, I don't need to reload the page so I have plenty of return view, sorry for the bad explanation
okay, I found it, just suppress all(), I'll edit my answer

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.