I want to get role_id for my users from contact.Here is my datatable role_users
:https://imgur.com/a/d9wtBhB
Now I'm getting this from dd($myRole)
:
[{"role_id":"1","user_id":"146"}]
How can I be able to get role_id
for my contacts?Because I need to put role_id
ahead of the names. I'm sorry if this isn't right, but I am new in 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'));
View:
<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>