laravel 9 in_array():参数#2($ haystack)必须是类型阵列,null给定的
我正在研究Laravel 9项目,并且正在尝试添加员工访问密码阵列,但是每次输入正确的密码时,我都会遇到此错误: in_array():参数#2($ haystack)必须是类型数组,null给出的
是代码:
public function access(Request $request)
{
$access_pass = config('web.offlinePass');
if (!in_array($request->pass, $access_pass))
return back()->withErrors(['The password entered is incorrect!']);
session()->put('admins_only', $request->pass);
session()-save();
return redirect()->route('website.dash.dash');
}
I'm working on a Laravel 9 project and I'm trying to add arrays of staff access passcodes but I keep getting this error every time I type in the correct passcode: in_array(): Argument #2 ($haystack) must be of type array, null given
Heres the code:
public function access(Request $request)
{
$access_pass = config('web.offlinePass');
if (!in_array($request->pass, $access_pass))
return back()->withErrors(['The password entered is incorrect!']);
session()->put('admins_only', $request->pass);
session()-save();
return redirect()->route('website.dash.dash');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Pulluck方法返回一个集合,这不是数组。
Pluck method return a collection, which is not an array.
替换带有空数组的值null的数组。 (当然只有在null的情况下):
Replace your array, which has the value null with an empty array. (of course only if it is null):
您必须确保要检查的变量是一个数组,因此您可以使用
print_r($ variable_name)
在检查代码in_array()
之前对其进行验证。you have to make sure that the variable you are checking is an array, so you can verify it with
print_r($variable_name)
before checking codein_array()