Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Error count():参数必须是使用laravel返回视图实现可计数的数组或对象_Arrays_Laravel - Fatal编程技术网

Arrays Error count():参数必须是使用laravel返回视图实现可计数的数组或对象

Arrays Error count():参数必须是使用laravel返回视图实现可计数的数组或对象,arrays,laravel,Arrays,Laravel,我得到这个错误,说它不是一个会计师,但我不明白为什么会发生这种情况,如果有人能给我一个帮助,我会很感激 代码控制器 $errors = 'You do not have sufficient permissions to access this page.'; return view('albaranes/index',[ "errors"=>$errors, ]); 查看、显示错误 <div class

我得到这个错误,说它不是一个会计师,但我不明白为什么会发生这种情况,如果有人能给我一个帮助,我会很感激

代码控制器

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

        return view('albaranes/index',[
            "errors"=>$errors,
        ]);
查看、显示错误

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

@如果($errors->any())
    @foreach($errors->all()作为$error)
  • {{$error}}
  • @endforeach
@恩迪夫
您需要知道,您已经向视图传递了一个字符串,但您使用的是错误作为对象,正如Qirel提到的,它是由laravel使用的。您可以覆盖它,这应该
fix
it

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

@如果(isset($errors))
    @如果(!is_字符串($errors)) @foreach($errors->all()作为$error)
  • {{$error}}
  • @endforeach @否则
  • {{$errors}}
  • @恩迪夫
@恩迪夫
$errors
在Laravel中保留,它与验证绑定。
$errors
在这里是一个字符串,但您将其用作对象(我猜是一个ErrorBag?)。