我具有搜索功能,我想where
为结果添加条件。
这是我的看法
@foreach($users as $user)
<li class="col-sm-4 col-xs-6 md-margin-bottom-30">
<div class="team-img">
@if((isset($user['profile_picture'])) && !empty($user['profile_picture']))
@if($user['facebook_id'] == 0)
<?php $img = "thumbnail/".$user['profile_picture']; ?>
@if(@getimagesize($img))
<img class="img-responsive profile-img margin-bottom-20" src="{{ url('ass/263/255?'.$img) }}" alt="">
@else
<?php $img = "assets/img/team/img10-md.jpg"; ?>
<img class="img-responsive" src="{{ url('ass/263/255?'.$img) }}" alt="">
@endif
@else
<?php $img = $user['profile_picture']; ?>
@if(@getimagesize($img))
<img class="img-responsive profile-img margin-bottom-20" src="{{ url('ass/263/255?'.$img) }}" alt="" >
@else
<?php $img = "assets/img/team/img10-md.jpg"; ?>
<img class="img-responsive" src="{{ url('ass/263/255?'.$img) }}" alt="">
@endif
@endif
@else
<?php $img = "assets/img/team/img10-md.jpg"; ?>
<img class="img-responsive" src="{{ url('ass/263/255?'.$img) }}" alt="">
@endif
<ul class="social-icons social-icons-color social-cu-icons" style="display:none;">
<div class="social-cu">
<li class="facebook_share share_link" link="{{ url('') }}/{{ $user['username'] }}" name="{{ $user['username'] }}">
<a href="#" data-original-title="Facebook" class="rounded social_facebook"></a>
</li>
<li class="google_share share_link" link="{{ url('') }}/{{ $user['username'] }}" name="{{ $user['username'] }}">
<a href="#" data-original-title="Google Plus" class="rounded social_googleplus"></a>
</li>
<li class="twitter_share share_link" link="{{ url('') }}/{{ $user['username'] }}" name="{{ $user['username'] }}">
<a href="#" data-original-title="Twitter" class="rounded social_twitter"></a>
</li>
<li class="whatapp_share share_link" link="{{ url('') }}/{{ $user['username'] }}" name="{{ $user['username'] }}">
<img class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/Whatsapp.png') }}" alt="">
</li>
</div>
</ul>
<ul>
@if(Sentinel::check())
@if(!in_array($user['id'], $invitation))
<li class="sendinvitation" value="{{ $user['id'] }}" id="sendinvitation">
<a href="javascript:void(0)">
<i class="icon-custom icon-sm rounded-x fa fa-user-plus {{ $user['id'] }} " style="border-radius: 4px !important"></i>
</a>
</li>
@endif
@else
<li class="sendinvitation1" value="{{ $user['id'] }}" id="sendinvitation">
<a href="javascript:void(0)" onClick="return loginConf();">
<i class="icon-custom icon-sm rounded-x fa fa-user-plus {{ $user['id'] }} " style="border-radius: 4px !important"></i>
</a>
</li>
@endif
@if(Sentinel::check())
<li class="send-contact-message" data-username="{{ $user['username'] }}" data-user-id="{{ $user['id'] }}">
<a href="javascript:void(0)"><i class="icon-custom icon-sm rounded-x fa fa-paper-plane-o" style="border-radius: 4px !important"></i></a>
</li>
@else
<li class="send-contact-message1" data-user-id="{{ $user['id'] }}">
<a href="javascript:void(0)" onClick="return loginConf();"><i class="icon-custom icon-sm rounded-x fa fa-paper-plane-o" style="border-radius: 4px !important"></i></a>
</li>
@endif
<li class="share-link"><a href="javascript:void(0)" ><i class="icon-custom icon-sm rounded-x fa fa-share-alt" style="border-radius: 4px !important"></i></a></li>
</ul>
</div>
<h3 style="margin-top: 20px !important;text-transform: none"><a href="{{ url('') }}/{{ $user['username'] }}">
@if($user['role'][0]['slug'] == "organizations")
<i style="font-size: 11px" class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
@else
<i style="font-size: 11px" class="icon-user"></i>
@endif
{{ $user['username'] }} </a></h3><p>
<strong><i class="icon-real-estate-020 u-line-icon-pro"></i> : </strong>{{ $user['country']['country'] }} <span class="{{ $user['country']['flag'] }}"></span><br>
@if(!empty($user['role']))
@if($user['role'][0]['slug'] == "organizations")
<strong><i class="icon-screen-tablet fa-" aria-hidden="true"></i> : </strong>{{ $user['industry']['industry'] }}<br>
@endif
@if($user['role'][0]['slug'] == "individuals")
<?php $career_path = array_reverse($user['career_path']); ?>
@if($career_path)
<strong><i class="icon-screen-tablet fa-" aria-hidden="true"></i> : </strong>{{ $career_path[0]['industry']['industry'] }}<br>
@else
<strong><i class="icon-screen-tablet fa-" aria-hidden="true"></i> : </strong><br>
@endif
@endif
@else
<strong><i class="icon-screen-tablet fa-" aria-hidden="true"></i> : </strong><br>
@endif
@if(!empty($user['role']))
@if($user['role'][0]['slug'] == "organizations")
<strong><i class="icon-frame fa-" aria-hidden="true"></i> : </strong>{{ $user['organization_type']['organization_type'] }}<br>
@elseif($user['role'][0]['slug'] == "individuals")
<?php $career_path = array_reverse($user['career_path']); ?>
@if($career_path)
@foreach($career_path as $careerpath)
<!-- <strong>Company:</strong>{{ $careerpath['company'] }}<br> -->
<strong><i class="icon-speedometer fa-" aria-hidden="true"></i> : </strong>{{ $careerpath['functions']['function'] }}
@break;
@endforeach
@else
<strong><i class="icon-speedometer fa-" aria-hidden="true"></i> : </strong>
@endif
@endif
@else
<strong><i class="icon-speedometer fa-" aria-hidden="true"></i> : </strong>
@endif
</p>
<br>
</li>
@endforeach
$users = User::with('country','industry','organization_type','career_path','career_path.industry','career_path.department','career_path.functions','role');
$private = DB::table('privacy_settings')->get();
$private = (array) $private;
$data['users'] = $users->orderBy('id', 'DESC')->skip($offset)->take($perPage)->get()->toArray();
因此,dd($private)
有了一个具有多个值的数组,但是我只需要value city
。在我看来,我正在使用foreach function
,并{{$private->city}}
显示每个用户的价值。
现在,$data['users']
如果可能的话,我想在其中添加类似的内容:where($private->city, '!=', 1)
。那应该只显示与的联络人$private->city == 0
。
dd($ data ['users'])
array:12 [▼
0 => array:60 [▼
"id" => 559
"customer_stripe_id" => null
"username" => "Mihail22"
"name" => "Mihail22"
"first_name" => null
"last_name" => null
"dob" => "0000-00-00"
"city" => ""
"telephone" => ""
"address" => ""
"website1" => ""
这city
是城市的名字
dd($ private)
array:297 [▼
0 => {#954 ▼
+"id": "142"
+"user_id": "559"
+"email": "1"
+"website": "1"
+"phone": "1"
+"address": "1"
+"city": "1"
+"current_job": "1"
+"job_history": "1"
+"education_history": "1"
+"career_solutions": "1"
+"profile_updates": "0"
+"contacts_list": "1"
+"groups": "1"
}
1 => {#953 ▶}
这city
是为了保护隐私(1-公共,0-私人)
您可以构建一个查询,以选择user_id
所有privacy_settings
位置city == 0
。然后,您可以通过传递之前构建WHERE IN
的$users
查询,将a添加到查询中以将其限制为仅具有这些ID的用户:
$user_ids_query = DB::table('privacy_settings')
->where('city', 0)
->select('user_id');
$data['users'] = $users->whereIn('id', $user_ids_query)
->orderBy('id', 'DESC')
->skip($offset)
->take($perPage)
->get()
->toArray(); // to match what you expect
这看起来像是建立关系并使用现有方式的不错选择。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句