在我的用户共享文档下方的表单中与其他用户共享文档。
如何增加我的选择器以仅向我显示未与此文档共享的用户? Document
和User
具有数据透视表document_user
<select type="text" name="user" class="uk-select">
<option disabled selected>Choose from contacts</option>
@foreach($company->users as $contact)
//@if (something)
<option value="{{ $contact->id }}">{{ $contact->first_name}} {{ $contact->last_name}}</option>
@andif
@endforeach
</select>
Document = $ document
表:
用户:
文件:
document_user: - company_id - user_id
答案 0 :(得分:1)
试试这个..
从您的表格结构中我相信您应该拥有many to many
关系。
<强> user.php的强>
public function documents()
{
return $this->belongsToMany(Document::class, 'document_user');
}
<强> xx.blade.php 强>
<select type="text" name="user" class="uk-select">
<option disabled selected>Choose from contacts</option>
@foreach($company->users as $contact)
@if(!in_array($contact->id, $document->users->pluck('id')->toArray()))
<option value="{{ $contact->id }}">
{{ $contact->first_name}} {{ $contact->last_name}}
</option>
@endif
@endforeach
</select>