Я хочу получить role_id для моих пользователей из списка контактов. Вот мои данные role_users
: https://imgur.com/a/d9wtBhB
Теперь я получаю это от dd($myRole)
:
[{"role_id":"1","user_id":"146"}]
Как я могу получить role_id
для своих контактов? Потому что мне нужно поставить role_id
перед именами. Извините, если это не правильно, но я новичок в php.
Controller.php :
$myRole = User::join(
'role_users',
function($join) {
$join->on('role_users.role_id', '=', 'users.id');
}
)
->selectRaw(
implode(',', [
'role_users.role_id AS role_id',
'count(users.id) AS user_id'
])
)
->get();
// dd($myRole);
return view('noticeboard.noticeboard',$data)
->with(compact('myRole'));
Вид:
<div class="tab-content">
<?php $count_contact_user = 1; ?>
@foreach($contact_users as $contact)
<div id="contact<?php echo $count_contact_user++; ?>" class="tab-pane magazine-sb-categories <?php if($count_contact_user == 2){ echo "active"; } ?>">
<div class="row team-v1">
<ul class="list-unstyled col-xs-12" style="margin-bottom: -10px">
<li><h3 style="margin-top: 5px !important;text-transform: none; "> <!-- @if($contact->organization_type=="organizations")
<i class="fa fa-building-o"></i>
@else
<i class="icon-user"></i>
@endif -->
{{$myRole}}
<a href="{{ url('') }}/{{ $contact->username }}">{{ $contact->username }}</a></h3>
<p>
<strong><i class="icon-real-estate-020 u-line-icon-pro"></i> : </strong><a href="#">{{ $contact->country }}</a><br>
<strong><i class="icon-screen-tablet fa-" aria-hidden="true"></i> : </strong><a href="#">{{ $contact->industry }}</a><br>
<strong><i class="icon-frame fa-" aria-hidden="true"></i> : </strong><a href="#">{{ $contact->organization_type }}</a><br>
</p>
</ul>
</div>