繁体   English   中英

如何在Laravel 5.2中显示我的表数据

[英]how to display My table data in Laravel 5.2

我的Laravel应用中有合作者表格,请参阅以下内容 在此处输入图片说明

我需要在我的index.blade.php文件中打印collaborator_id,该文件相当于Auth :: user()-> id才能与系统一起登录。 我在“我的协作模型”中编写了以下代码

public function scopeColabo($query){
 return $query->where('collaborator_id',Auth::user()->id);}

这是我的ProjectCollaboratorController函数

public function index(){
$collaborators = Collaboration::colabo()->getreturn view('collaborators.index')->withCollaboration($collaborators);}

这是我的index.blade.php

<div class="container">
@if($collaboration)
<div class="row">
         @foreach ($collaboration as $proj)
           <div class="col-md-3" style="border:1px solid #ccc;margin-left:5px;">
           <h2><a href="/projects/{{ $proj->id }}">{!! $proj->project_id !!}</a></h2>

           <p>Tasks: 0</p>
           <p>Comments: 0</p>
           <p>Attachments: 0</p>
           </div>

        @endforeach
     </div>
  @endif



   @if($collaboration->isEmpty())
     <h3>There are currently no Collaboration</h3>
@endif 
</div>

但是当我单击协作链接index.blade.php文件生成时

There are currently no Projects

但是在“我的表”中有数据。...如何与当前登录用户一起在协作表中打印collaborator_id?

尝试使用-> with()代替-> withCollaboration

public function index() {
    $collaborators = Collaboration::colabo()->get();
    return view('collaborators.index')->with(compact('collaborators'));
}

或只是将您的数据作为第二个参数传递:

public function index() {
    $collaborators = Collaboration::colabo()->get();
    return view('collaborators.index', compact('collaborators'));
}

问题出在表中的collaborator_id ,该表用于登录以测试系统:

在测试中,在记录帐户中,数据应与协作者数据匹配,因此collaborator_id应与记录的用户ID匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM