ErrorException (E_NOTICE) 未定义的偏移量:0 laravel
ErrorException (E_NOTICE) Undefined offset: 0 laravel
我正在尝试从数据库中读取数据并将数据显示到表单中,但我一直收到此错误。
这是我的控制器:
public function create()
{
/* this function gets data from the database (marks table) and render it to the view view */
$data['data']=DB::table('marks')->get();
if(count($data[0])>0){
return view('view',$data);
}
else{
return view('view');
}
}
这就是我定义路线的方式:
Route::resource('claude', 'viewcontroller');
变量 $data
没有 0
的索引。
但它有一个名为 data
.
的键
所以你必须通过密钥访问它。
应该是
if(count($data['data']) > 0){
return view('view',$data);
}
get()
会return一个集合,你可以通过
检查它是否有项目
if ($data['data']->count()) {
return view('view',$data);
} else {
return view('view');
}
if(is_array($data) && isset($data)){
return view('view',$data);
}
我正在尝试从数据库中读取数据并将数据显示到表单中,但我一直收到此错误。
这是我的控制器:
public function create()
{
/* this function gets data from the database (marks table) and render it to the view view */
$data['data']=DB::table('marks')->get();
if(count($data[0])>0){
return view('view',$data);
}
else{
return view('view');
}
}
这就是我定义路线的方式:
Route::resource('claude', 'viewcontroller');
变量 $data
没有 0
的索引。
但它有一个名为 data
.
的键
所以你必须通过密钥访问它。
应该是
if(count($data['data']) > 0){
return view('view',$data);
}
get()
会return一个集合,你可以通过
if ($data['data']->count()) {
return view('view',$data);
} else {
return view('view');
}
if(is_array($data) && isset($data)){
return view('view',$data);
}