简体   繁体   English

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

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

I have collaborators table in My Laravel app see this following 我的Laravel应用中有合作者表格,请参阅以下内容 在此处输入图片说明

I need collaborator_id print in My index.blade.php file who equel with Auth::user()->id to logged with the system. 我需要在我的index.blade.php文件中打印collaborator_id,该文件相当于Auth :: user()-> id才能与系统一起登录。 I wrote following code in My Collaboration Model 我在“我的协作模型”中编写了以下代码

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

and this is My ProjectCollaboratorController function 这是我的ProjectCollaboratorController函数

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

and this is My index.blade.php 这是我的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>

But when I click collaboration link index.blade.php file generate 但是当我单击协作链接index.blade.php文件生成时

There are currently no Projects

but in My table there is data....how can print collaborator_id in collaboration Table relete with current logged user? 但是在“我的表”中有数据。...如何与当前登录用户一起在协作表中打印collaborator_id?

Try to use ->with() instead of ->withCollaboration : 尝试使用-> with()代替-> withCollaboration

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

or just pass your data as second parameter: 或只是将您的数据作为第二个参数传递:

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

The problem is with the collaborator_id in the table which is used to log to test the system: 问题出在表中的collaborator_id ,该表用于登录以测试系统:

In the tests, in the logging account, data should match with collaborator data, so collaborator_id should match with the logged user id. 在测试中,在记录帐户中,数据应与协作者数据匹配,因此collaborator_id应与记录的用户ID匹配。

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

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