Laravel - 'array_merge(): Argument #2 is not an array' 当我不再使用数组时发生

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38862076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:17:05  来源:igfitidea点击:

Laravel - 'array_merge(): Argument #2 is not an array' occurring when i'm not using an array anymore

phparrayslaravel

提问by AndrewMMG

I was using arrays to pass data back to a view from a controller, but now have switched to using just strings, however this error pops up.

我使用数组将数据从控制器传递回视图,但现在已切换到仅使用字符串,但是会弹出此错误。

" array_merge(): Argument #2 is not an array "

“ array_merge():参数#2 不是数组”

I'm not even using an array anymore, and i've done php artisan clear:cache incase there was some cache I didn't know about. I'm new to laravel but all the results I find are dealing with people incorrectly using arrays, whereas i'm just passing a simple string.

我什至不再使用数组了,而且我已经完成了 php artisan clear:cache 以防有一些我不知道的缓存。我是 laravel 的新手,但我发现的所有结果都在处理错误地使用数组的人,而我只是传递一个简单的字符串。

Can somebody please help? Below is my code

有人可以帮忙吗?下面是我的代码

section of code in controller

控制器中的代码部分

else {
                $result = 'That email belongs to an existing referrer.';
                return view('admin.invalidReferrer', $result);

section of code in invalidReferrer.blade.php@extends('admin.admin')

invalidReferrer.blade.php@extends('admin.admin') 中的代码部分

@section('results')

<h4>{{ $result }}</h4>


@stop

previous controller solution

以前的控制器解决方案

else {
    $result = ['That email belongs to an existing referrer.'];
    return view('admin.invalidReferrer', compact('result'));

previous blade solution

以前的刀片解决方案

@section('results')

<h4>{{ $result[0] }}</h4>

@stop

采纳答案by Kevin

Just use the previous solution but remove the superfluous array assignment.

只需使用以前的解决方案,但删除多余的数组分配。

Instead of using:

而不是使用:

$result = ['That email belongs to an existing referrer.']; // shorthand array assignment of string to index 0
// ^ unneeded array assignment ^

Just assign the string directly:

直接分配字符串即可:

$result = 'That email belongs to an existing referrer.';
return view('admin.invalidReferrer', compact('result'));

Then use the imported data normally as you would:

然后像往常一样使用导入的数据:

@section('results')

<h4>{{ $result }}</h4>

@stop

回答by Harry

Just follow this instructions:

只需按照以下说明操作:

  1. Remove config.phpand service.phpfile from bootstrap.
  2. run php artisan serve
  3. run ctrl+con terminal after php artisan serve
  4. and run composer update
  1. 从引导程序中删除config.phpservice.php文件。
  2. 运行php artisan serve
  3. php artisan serve后在终端上运行ctrl+c
  4. 并运行作曲家更新

fixed for me.

为我固定。