我想设置一个条件,我需要检查当前用户,如果他/他是文档的批准者。如果用户是批准者接受和拒绝按钮将显示到视图。如何比较身份验证::检查()基于哪里条款
控制器:
public function documentsSentForApproval()
{
$pendingDocumentLists = DB::table('approve_document')->select('documents.title', 'documents.content',
'categories.category_type', 'users.username', 'approve_document.dateReceived', 'documents.id')
->join('documents', 'documents.id', '=', 'approve_document.document_id')
->join('categories', 'categories.id', '=', 'documents.category_id')
->join('approves', 'approves.id', '=', 'approve_document.approve_id')
->join('users', 'users.id', '=', 'approves.approver_id')
->where('approver_id', '=', Auth::id())
->orWhere('requestedBy', '=', Auth::id())
->get();
return view ('document.pending')
->with('pendingDocumentLists', $pendingDocumentLists);
}
正如你可以在这里看到的where
子句approver_id
的是谁要去批准文件之一。我只是在requestedBy
列是创建批准文档的那个小问题。
逻辑:
我需要检查,如果当前用户!= approver_id
。如果不是接受和拒绝将不会显示到视图。
查看:
<table class = "table">
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Category</th>
<th>Approver</th>
<th>Date Sent</th>
<th>Action</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach ($pendingDocumentLists as $list)
<tr class = "info">
<td>{{ $list->title }}</td>
<td>{{ strip_tags(substr($list->content, 0, 50)) }} {{ strlen($list->content) > 50 ? "..." : '' }}</td>
<td>{{ $list->category_type }}</td>
<td>{{ $list->username }}</td>
<td>{{ date('M, j, Y', strtotime($list->dateReceived)) }}</td>
<td>
<a href = ""><button type = "submit" class = "btn btn-primary glyphicon glyphicon-open"> Read</button></a>
<button type = "submit" class = "btn btn-danger glyphicon glyphicon-trash"> Delete</button>
@if (Auth::check() ==)<!--I'm stuck here-->
<button type = "submit" class = "btn btn-success glyphicon glyphicon-thumbs-up"> Approve</button>
<button type = "submit" class = "btn btn-warning glyphicon glyphicon-thumbs-down"> Reject</button>
@endif
</td>
</tr>
@endforeach
</tbody>
用户界面:
更新
我加入$data['permission'] = ['approver_id'];
作为@Mayank说,这是我在我看来所做的。
<tbody>
@foreach ($pendingDocumentLists as $list)
<tr class = "info">
<td>{{ $list->title }}</td>
<td>{{ strip_tags(substr($list->content, 0, 50)) }} {{ strlen($list->content) > 50 ? "..." : '' }}</td>
<td>{{ $list->category_type }}</td>
<td>{{ $list->username }}</td>
<td>{{ date('M, j, Y', strtotime($list->dateReceived)) }}</td>
<td>
@if ($permission != Auth::id())
<a href = ""><button type = "submit" class = "btn btn-primary glyphicon glyphicon-open"> Read</button></a>
<button type = "submit" class = "btn btn-danger glyphicon glyphicon-trash"> Delete</button>
@else
<button type = "submit" class = "btn btn-success glyphicon glyphicon-thumbs-up"> Approve</button>
<button type = "submit" class = "btn btn-warning glyphicon glyphicon-thumbs-down"> Reject</button>
@endif
</td>
</tr>
@endforeach
</tbody>
不能使用$列表 - > approve_id ==验证:: ID()? – KmasterYC
尝试将其添加到选择语句 – KmasterYC
它已经工作。我刚刚在我的选择中添加了“approves.approves_id”。 – Francisunoxx