laravel- 未定义索引 ID
laravel- undefined index id
我是 laravel 的新手,正在构建一个简单的应用程序。我在我的控制器中使用这个功能:
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
//
//return view('adminlte::home');
$user= Auth::user()->id;
$csafe = csafe::where('username','=', $user->email)->get();
return view('csaves.show', array('csafe' => $csafe));
}
thr table csaves 有两行具有不同 ID (PK) 的数据,用于我登录的用户。
但是当我在网络浏览器中调出视图时,出现以下错误:
Undefined index: id
在我看来 blade 我拥有的文件:
@foreach ($csafe->id as $id)
<h1>csafe {{ $id }}</h1>
@endforeach
如何在此视图中使用所选条件显示数组 /table 的所有值?
如果您能指导我如何将其放入网格或图表中,我将不胜感激。
您只有一个 csafe,因此您不应该使用 foreach 循环。只需使用这个:
<h1>csafe {{ $csafe->id }}</h1>
我认为你需要这样做
@foreach ($csafe as $c)
<h1>csafe {{ $c->id }}</h1>
@endforeach
首先,我想知道user
是否有很多csafe
?如果是,请像这样修改您的索引方法
public function index()
{
//
//return view('adminlte::home');
$user= Auth::user();
$csafe = csafe::where('id','=', $user->id)->get();
return view('csaves.show', compact('csafe'));
}
在你的视野中
@foreach ($csafe as $c)
<h1>csafe {{ $c->id }}</h1>
@endforeach
我是 laravel 的新手,正在构建一个简单的应用程序。我在我的控制器中使用这个功能:
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
//
//return view('adminlte::home');
$user= Auth::user()->id;
$csafe = csafe::where('username','=', $user->email)->get();
return view('csaves.show', array('csafe' => $csafe));
}
thr table csaves 有两行具有不同 ID (PK) 的数据,用于我登录的用户。 但是当我在网络浏览器中调出视图时,出现以下错误:
Undefined index: id
在我看来 blade 我拥有的文件:
@foreach ($csafe->id as $id)
<h1>csafe {{ $id }}</h1>
@endforeach
如何在此视图中使用所选条件显示数组 /table 的所有值?
如果您能指导我如何将其放入网格或图表中,我将不胜感激。
您只有一个 csafe,因此您不应该使用 foreach 循环。只需使用这个:
<h1>csafe {{ $csafe->id }}</h1>
我认为你需要这样做
@foreach ($csafe as $c)
<h1>csafe {{ $c->id }}</h1>
@endforeach
首先,我想知道user
是否有很多csafe
?如果是,请像这样修改您的索引方法
public function index()
{
//
//return view('adminlte::home');
$user= Auth::user();
$csafe = csafe::where('id','=', $user->id)->get();
return view('csaves.show', compact('csafe'));
}
在你的视野中
@foreach ($csafe as $c)
<h1>csafe {{ $c->id }}</h1>
@endforeach