簡體   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