douwu7563 2019-07-03 12:03
浏览 16

如何为每个用户获得角色?

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线