简体   繁体   中英

how to display My table data in Laravel 5.2

I have collaborators table in My Laravel app see this following 在此处输入图片说明

I need collaborator_id print in My index.blade.php file who equel with Auth::user()->id to logged with the system. 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

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

and this is My 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

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?

Try to use ->with() instead of ->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:

In the tests, in the logging account, data should match with collaborator data, so collaborator_id should match with the logged user id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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