Call to a member function all() on string laveral

Issue

Am following tutorials in youtube on laravel, am using laravel 5.6.
I get an error when try display error
here the codes

This is the view

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

This is the Controller

  return back()->withInput()->with('errors', 'Error creating new company');

So I don’t know where I went wrong Somebody could help me

Solution

Check and display in session

 return redirect()->back()->withInput()->with('errors', 'Error creating new company');

Display in template

@if(session('errors'))
     {{session('errors')}}
@endif

You are displaying single error so No need to add @foreach

Answered By – Niklesh Raut

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published