Call to a member function all() on string laveral


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>
            @foreach ($errors->all() as $error)
                <li><strong>{!! $error !!}}</strong></li>

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


Check and display in session

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

Display in template


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