将get()与Laravel 5结合使用

时间:2019-03-27 13:34:16

标签: php laravel

我有一个Laravel 5应用,我试图从两个不同的表中获取数据:端点表和审计表。他们通过Endpoints.id和Audits.endpoint_id相互引用。我正在尝试针对该特定端点进行审核,但一直遇到诸如Too few arguments to function Illuminate\Support\Collection::get()

之类的错误

这是我的文件:

OnDemandController.php

public function index()
{

$endpoints = auth()->user()->endpoints->where('is_ondemand', true);

$endpoint = $endpoints->get();

$mobileAudits = $endpoint->audits()->where('strategy', 'mobile')->first();
$desktopAudits = $endpoint->audits()->where('strategy', 'desktop')->first();        

return view('ondemand.index', compact('endpoints', 'mobileAudits', 'desktopAudits'));

}

index.blade.php

  @forelse($endpoints as $endpoint)
  {{ $desktopAudits->id }} - {{ $mobileAudits->id }}
  @empty
  nope
  @endforelse

端点模型

protected $guarded = [];

protected $requestedAudits = null;

public function audits()
{
    return $this->hasMany(Audit::class);
}

任何帮助将不胜感激。

谢谢!

0 个答案:

没有答案