laravel非法偏移类型错误 [英] laravel Illegal offset type error

查看:73
本文介绍了laravel非法偏移类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,显示单个测试用例的详细信息.由于某些原因,即使发送$id,我也无法克服此错误.这是我的控制器:

I have a page that shows the details of a single test case. For some reason, I can't get past this error, even to send the $id. Here's my controller:

public function show($id)
{
    $data =DB::table('TestCase')->where('TestCaseID', $id);
    return view('managements.testcase-details')->with($data);
}

这是错误:

在View.php第180行中的

在HandleExceptions-> handleError('2','Illegal offset type','C:\ xampp \ htdocs \ terkwazmng \ vendor \ laravel \ framework \ src \ Illuminate \ View \ View.php','180',array('键'=> object(Builder),'value'=> null))

in View.php line 180 at HandleExceptions->handleError('2', 'Illegal offset type', 'C:\xampp\htdocs\terkwazmng\vendor\laravel\framework\src\Illuminate\View\View.php', '180', array('key' => object(Builder), 'value' => null))

推荐答案

您忘记了一点. get和要设置的数据变量名称.您的错误意味着,您传递的是查询生成器而不是其结果.第二个错误是您传递了NULL值(with中的第二个参数).

You forgot a little bit. A get and to set up data variable name. Your error means, that you pass a query builder rather than its results. The second error is that you passing a NULL value (second param in with).

$data =DB::table('TestCase')->where('TestCaseID', $id)->get();
return view('managements.testcase-details')->with('data', $data);

在视图中使用data就像使用数组:foreach($data ...).

In view use data like you use an array: foreach($data ...).

这篇关于laravel非法偏移类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆