Removeclass in foreach with jquery - php

when I click on a profile in the foreach loop, the "active" property of all "active" classes is deleted, not just the profile I clicked. How can I fix it so that only what I click is deleted? I do not want all "active" classes to be deleted, but only the active class property you clicked.
#foreach($other_user['details'] as $user)
#php
$user_id = Auth::user()->id;
$withid= $user->id;
$getunreadcount = \Models\Members::getlastconverunread($user_id,$withid);
#endphp
<a href="javascript:void(0);" data-conversation="{{$user->lastConver != null ? 'true' :'false'}}" data-id="{{ $user->username }}" #if($getunreadcount > 0) class="list-group-item list-group-item-action border-0 active userlink {{$user->lastConver != null ? ' ' :'hidden'}}" #else class="list-group-item list-group-item-action border-0 userlink {{$user->lastConver != null ? ' ' :'hidden'}}" #endif >
<div class="d-flex align-items-start">
#if($user->user_photo!='')
<img src="{{ url('/') }}/public/storage/users/{{ $user->user_photo }}" class="rounded-circle mr-1" alt="{{ $user->username }}" width="40" height="40">
#else
<img class="rounded-circle mr-1" width="40" height="40" src="{{ url('/') }}/public/img/no-user.png" alt="{{ $user->username }}" />
#endif
<div class="flex-grow-1 ml-3">
<span class="userName">
{{ $user->username }}
</span>
#if($getunreadcount > 0)
<div class="small unread"><span class="badge badge-warning">{{$getunreadcount}} Yeni Mesaj</span></div>
#endif
</div>
</div>
</a>
#endforeach
JQUERY:
$('.userlink').click(function(e) {
e.preventDefault();
var id = $(this).data("id");
var token = $("meta[name='csrf-token']").attr("content");
$('.userlink').removeClass('active');
var $this = $(this);
if (!$this.hasClass('active')) {
$this.removeClass('active');
}
});
I will be glad if you help me thank you.

$('.userlink').click(function(e) {
e.preventDefault();
...
// Like this:
$(this).removeClass('active');
});

Related

How to add a where condition with a variable to my controller?

I have a search function and I want to add a where condition for results.
Here is my view
#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'] }}">
</li>
<li class="google_share share_link" link="{{ url('') }}/{{ $user['username'] }}" name="{{ $user['username'] }}">
</li>
<li class="twitter_share share_link" link="{{ url('') }}/{{ $user['username'] }}" name="{{ $user['username'] }}">
</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'] }}">
<i class="icon-custom icon-sm rounded-x fa fa-paper-plane-o" style="border-radius: 4px !important"></i>
</li>
#else
<li class="send-contact-message1" data-user-id="{{ $user['id'] }}">
<i class="icon-custom icon-sm rounded-x fa fa-paper-plane-o" style="border-radius: 4px !important"></i>
</li>
#endif
<li class="share-link"></i></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();
So, with dd($private) I have an array with multiple values, but I need only value city. In my view I'm using a foreach function, and {{$private->city}} to display value of every user.
Now, I want to add something like that in $data['users'], if it's possible : where($private->city, '!=', 1) . That's should display only contacts with $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" => ""
Here city is the name of 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 ▶}
Here city is for privacy ( 1 - public, 0 - private )
You can build a query that selects the user_id of all privacy_settings where city == 0. You can then add a WHERE IN to the $users query to limit it to only users with those ids by passing in the previous query being built:
$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
This looks like a good candidate for setting up a relationship and using what is available that way as well.
Try
$private = DB::table('privacy_settings')->where("city",0)->get();
print_r($private);
$data['users'] = $users->where("city",0)->orderBy('id', 'DESC')->skip($offset)->take($perPage)->get()->toArray();
print_r($data['users']);

Avoid refreshing the page at pagination

I want to avoid refreshing page when i switch the pages using pagination from Laravel because when I switch the page from 1 to page 2, It redirects to the parent page. How can I avoid reloading page when i switch the pages? I have 2 tabs at Invitation - Received and Initiated. On Initiated, I have pagination, when i press on page 2 for example, I get redirected to the parent page which is Invitation, I need to stay on the page Initiated when i switch the page from pagination.
Here is my controller:
$initiated = \App\Invitation::with('user')
->where('inviter_id', Sentinel::getUser()->id)
->orderBy('id', 'desc')
->paginate(6);
Here is my view:
<div id="initiated" class="profile-edit tab-pane fade" style="background: none repeat scroll 0 0;">
<dl class="dl-horizontal">
<ul class="nav justify-content-center u-nav-v5-3 u-nav-primary " role="tablist"
data-target="nav-5-3-primary-hor-center" data-tabs-mobile-type="slide-up-down"
data-btn-classes="btn btn-md btn-block u-btn-outline-primary"
style="display: flex;justify-content: flex-end;">
<li class="nav-item active">
<a a data-toggle="tab" href="#grid" style="font-size: 12px"><i class="fa fa-th-large"></i> Grid</a>
</li>
<li class="nav-item">
<a a data-toggle="tab" href="#list" style="font-size: 12px"><i class="fa fa-bars"></i> List</a>
</li>
</ul>
<div class="tab-content">
<div id="grid" class="tab-pane fade in active">
<?php $count_user = 0;
?>
#foreach($initiated as $record)
#if($count_user == 0)
<div class="row margin-bottom-20 ">
#endif
<?php $count_user++; ?>
<div class="col-sm-6 sm-margin-bottom-20">
<div class="profile-blog">
<img style="border-radius: 0% !important" class="rounded-x"
src="{{ asset('thumbnail') }}/{{ $record->user ? $record->user->profile_picture : '' }}"
alt="">
<div class="name-location" style="top: 30px;position: relative">
#if($record->user->role[0]->slug == 'individuals' ? $record->user->role[0]->slug : '')
<i style="font-size: 13px;position: relative;" class="icon-user"></i>
#elseif($record->user->role[0]->slug == 'organizations' ? $record->user->role[0]->slug :
'')
<i style="font-size: 13px;position: relative;"
class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
#endif
<a id="my-link" style="color: #555;text-decoration: none;font-size: 16px"
href="{{ url('') }}/{{ $record->user ? $record->user->username : '' }}">{{ $record->user ? $record->user->username : '' }}</a>
</h3>
</div>
<div class="clearfix "></div>
<strong style="font-size: 13px"><i style="padding: 5px"
class="icon-real-estate-020 u-line-icon-pro"></i>Location :
</strong>{{ $record->user ? $record->user->country->country : '' }} <span
class="{{ $record->user ? $record->user->country->flag : '' }}"></span><br>
<strong style="font-size: 13px"><i style="padding: 5px"
class="icon-notebook fa-"></i>Industry :
</strong>{{ $record->user ? $record->user->industry->industry : '' }}<br>
#if($record->user->role[0]->slug == 'organizations' ? $record->user->role[0]->slug : '')
#if(isset($record->user->organization_type->organization_type))
<strong style="font-size: 13px"><i
class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"
style="padding: 5px;font-size: 13px"></i>Organization :
</strong>{{ $record->user ? $record->user->organization_type->organization_type : '' }}#endif
#endif
#if($record->user->role[0]->slug == 'individuals' ? $record->user->role[0]->slug : '')
#if(!empty($record->user->career_path[0]))
<strong style="font-size: 13px"><i class="icon-speedometer"
style="padding: 5px"></i>Function :
</strong>{{ $record->user ? $record->user->career_path[0]->functions->function : '' }}#endif
#endif
<hr>
<ul class="list-inline share-list">
<li>
<i class="fa fa-times"> </i>Cancel
</li>
</ul>
</div>
</div>
#if($count_user == 2)
</div>
<?php $count_user = 0; ?>
#endif
#endforeach
</div>
<div id="list" class="tab-pane fade">
<?php $count_user = 0;
?>
#foreach($initiated as $record)
#if($count_user == 0)
<div class="row">
#endif
<?php $count_user++; ?>
<div class="col-sm-12 sm-margin-bottom-20" style="margin-bottom: 12px">
<div class="profile-blog" style="padding: 5px">
<img style="margin-right: 10px"
src="{{ asset('thumbnail') }}/{{ $record->user ? $record->user->profile_picture : '' }}"
alt="">
<div class="name-location">
<h3> #if($record->user->role[0]->slug == 'individuals' ? $record->user->role[0]->slug :
'')
<i style="font-size: 13px;position: relative;" class="icon-user"></i>
#elseif($record->user->role[0]->slug == 'organizations' ?
$record->user->role[0]->slug : '')
<i style="font-size: 13px;position: relative;"
class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
#endif <a id="my-link" style="color: #555;text-decoration: none;font-size: 16px"
href="{{ url('') }}/{{ $record->user ? $record->user->username : '' }}">{{ $record->user ? $record->user->username : '' }}</a>
</h3>
<ul class="list-inline share-list d-flex pull-right"
style="bottom: 25px;position: relative;margin-bottom: -20px;left: -25px">
<li style="left: 25px;position: relative">
<a href="/cancel-invitation/{{$record->id}}"><i
class="icon-custom-me rounded fa fa-times"> </i></a>
</li>
</ul>
</div>
<div style="display: flex;right: 2px;position: relative;bottom: 12px;margin-bottom: -10px">
<div style="padding-right: 15px">
<strong><i class="icon-real-estate-020 u-line-icon-pro"></i> :
</strong>{{ $record->user ? $record->user->country->country : '' }} <span
class="{{ $record->user ? $record->user->country->flag : '' }}"></span>
</div>
<div style="padding-right: 10px">
<strong><i class="icon-screen-tablet fa-"></i> :
</strong>{{ $record->user ? $record->user->industry->industry : '' }}
</div>
<div style="padding-right: 10px">
#if($record->user->role[0]->slug == 'organizations' ? $record->user->role[0]->slug :
'')
#if(isset($record->user->organization_type->organization_type))
<strong><i class="icon-speedometer"></i> :
</strong>{{ $record->user ? $record->user->organization_type->organization_type : '' }}
#endif
#endif
</div>
<div style="padding-right: 10px">
#if($record->user->role[0]->slug == 'individuals' ? $record->user->role[0]->slug :
'')
#if(!empty($record->user->career_path[0]))
<strong><i class="icon-frame fa-"></i> :
</strong>{{ $record->user ? $record->user->career_path[0]->functions->function : '' }}
#endif
#endif
</div>
</div>
</ul>
</div>
</div>
#if($count_user == 2)
</div>
<?php $count_user = 0; ?>
#endif
#endforeach
</div>
</div>
</dl>
{!! $initiated->render() !!}
</div>
Here is my Ajax:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$('.pagination a').on('click', function (e) {
e.preventDefault();
var url = $(this).attr('href');
$('#initiated').load(url + ' div#initiated');
});
</script>
You'd probably want to use jQuery's .load() on the actual element that you cares instead of rewriting the whole HTML. Perhaps something like this:
$('.pagination a').on('click', function (e) {
e.preventDefault();
var url = $(this).attr('href');
$('#initiated').load(url + ' div#initiated');
});
Remember to re-run this script everytime after new content is loaded with AJAX if the pagination links are rewritten. With the complete parameter in the .load() function, you can do this:
function ajaxPaging() {
$('.pagination a').on('click', function (e) {
e.preventDefault();
var url = $(this).attr('href');
$('#initiated').load(url + ' div#initiated', null, ajaxPaging); // re-run on complete
});
}
ajaxPaging();
Update: Unable to preventDefault inside passive event listener due to target being treated as passive.
You might run into this error on Chrome. To fix it, try this before your other script calls (reference):
(passiveSupported && (active || el == window.document || el == window.document.body || el == window)) ? el.addEventListener(name, fn, { passive: false, capture: bubble }) : el.addEventListener(name, fn, bubble || false);

Posts are not displaying correctly after deactivate

So, I have a problem with displaying for a few posts.After a post was deactivated, on main isn't showing anymore, but the space is still here, even if I have an #if condition.By default, on my page I have 7 posts on every page, but here is remaining only the posts which is activated ( table event, column activate)
Here is the code from main
<div class="clearfix margin-bottom-20"><hr></div>
<!-- News v3 -->
#foreach($events as $event)
#if($event->active != 1)
<div class="row margin-bottom-20">
<div class="col-sm-5 sm-margin-bottom-20">
<div class="easy-block-v1">
<a href="{{ url('topic') }}/{{ $event->category->category_url }}">
<div class="easy-block-v1-badge rgba-{{ $event->category->color }} noticeboard-topic-category">
<i class="icon-hotel-restaurant-183 u-line-icon-pro fa-"></i> / {{ $event->category->category }}
</div>
</a>
<?php
$video_content = preg_replace("/<img[^>]+\>/i", "", $event->information);
preg_match('/src="([^"]+)"/', $video_content, $video);
?>
<?php
$match = '';
$str = $event->information;
$start = "<iframe src='";
$end = "' width='100%' height='281'></iframe>";
$pattern = sprintf(
'/%s(.+?)%s/ims',
preg_quote($start, '/'), preg_quote($end, '/')
);
if (preg_match($pattern, $str, $matches)) {
list(, $match) = $matches;
}
?>
#if(isset($match) && $match != '')
<iframe src="{{ $match }}" width='100%' height='250'></iframe>
#elseif(isset($video[1]))
<iframe src="{{ $video[1] }}" width='100%' height='250'></iframe>
#else
<?php preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $event->information, $image); ?>
#if(isset($image['src']))
<!-- <img class="img-responsive" src="{{ $image['src'] }}" alt=""> -->
<?php $img = str_replace('&', '&', $image['src']); ?>
<img class="img-responsive" src="{{ url('ass/336/212?'.$img) }}" alt="">
#else
<?php $img = "thumbnail/".$event->user->profile_picture; ?>
#if(#getimagesize($img))
<img src="{{ url('ass/336/212?'.$img) }}" alt='' />
#else
<?php $img = "assets/img/main/img12.jpg"; ?>
<img class="img-responsive" src="{{ url('ass/336/212?'.$img) }}" alt="">
#endif
#endif
#endif
</div>
</div>
<div class="col-sm-7 news-v3">
<div class="news-v3-in-sm no-padding">
<h2>{{ $event->subject }}</h2>
<ul class="list-inline" style="right: 10px;position: relative">
<li style="font-style: normal !important">
<li style="font-style: normal !important">
#if($event->user->role[0]->pivot->role_id == 1)
<i style="margin-right: 2px;margin-left: 3px;font-size: 11px" class="icon-user"></i>
#else
<i style="margin-right: 2px;margin-left: 3px;font-size: 11px" class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
#endif
<a style="margin-left: 2px" href="{{ url('') }}/{{ $event->user->username }}">{{ $event->user->username }}</a></li>
<li style="font-style: normal !important"><i style="margin-right: 3px" class="icon-hotel-restaurant-183 u-line-icon-pro fa-"></i> <a href="{{ url('view-all-event') }}">Event</li>
<li style="font-style: normal !important"><i style="margin-right: 3px" class="icon-notebook fa-"></i> {{ $event->category->category }}</li>
</ul>
<?php
$information = preg_replace("/<img[^>]+\>/i", "", $event->information);
$Output = preg_replace('/<iframe.*?\/iframe>/i','', $information);
?>
<p>{{ str_limit(trim(strip_tags(preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $Output))), 200) }}</p>
<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('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}" name="{{ $event->subject }}" description="{{ $event->subject }}">
</li>
<li class="google_share share_link" link="{{ url('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}" name="{{ $event->subject }}" description="{{ $event->subject }}">
</li>
<li class="twitter_share share_link" link="{{ url('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}" name="{{ $event->subject }}" description="{{ $event->subject }}">
</li>
<li class="whatapp_share share_link" link="{{ url('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}" name="{{ $event->subject }}" description="{{ $event->subject }}">
<a href="whatsapp://send?text={{ url('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}">
<img class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/Whatsapp.png') }}" alt="">
</a>
</li>
</div>
</ul>
<ul class="post-shares post-shares-lg">
<li ><i class="rounded-x fa fa-comments-o "><span>{!! $event->event_comment_count !!}</span></i></li>
<li><i class="rounded-x icon-magnifier-add" ><span>{!! $event->views !!}</span></i></li>
<li class="changeview" value="{{ $event->id }}" id="changeview"><i class="rounded-x icon-like "><span class="like_{{ $event->id }}">{!! $event->event_like_count !!}</span></i></li>
<li class="share-link"><i class="rounded-x icon-share"></i></li>
</ul>
<br>
Read more...
</div>
</div>
</div><!--/end row-->
<!-- End News v3 -->
<div class="clearfix margin-bottom-20"><hr></div>
#endif
#endforeach
My controller
public function viewAllEvent($category_id = null,$event_type_id = null,$country_id = null,$starting_date = null,$username = null,$search = null,$page = null)
{
// $eventrecommended = Event::with('user','category','country','event_type','event_like')->withCount('event_like','event_comment')->whereHas('user.contact', function ($query) use ($id) {
// $query->where('contacts.user_id', '=', $id);
// })->orWhere('events.public', '=', 1)->orWhere('events.user_id', '=', $id);
// if($page == ""){
// return redirect('view-all-event/1');
// }
$data = $this->data;
$data['title'] = "View All Event";
$data['breadcrumbs'] = "Events";
$page = Input::get('page');
$perPage = 7;
$offset = ($page * $perPage) - $perPage;
$data['evnetTypeList'] = \App\EventType::all();
$data['countryList'] = [''=>'Country'] + \App\Country::lists('country','code')->toArray();
$data['category'] = Input::get('category');
$data['event_type'] = Input::get('event_type');
$data['country'] = Input::get('country');
$data['starting_date'] = Input::get('starting_date');
$username = Input::get('username');
$search = Input::get('search');
$data['login_user'] = $username;
$data['search'] = $search;
$categoryID = \App\Category::pluck('id');
$event = Event::with('user','category','country','event_type')->withCount('event_like','event_comment')->whereHas('user', function($query) {
$query->where('deleted_at', '=', null);
})->whereIn('category_id',$categoryID);
$eventrecommended = Event::with('user','category','country','event_type','event_like')->whereHas('user', function($query) {
$query->where('deleted_at', '=', null);
})->withCount('event_like','event_comment')->whereIn('category_id',$categoryID);
if ($user = Sentinel::check())
{
if(!$user->inRole('admins'))
{
$id = $user->id;
$event = $event->Where(function($query1) use($id){
$query1->where('public','=', 1)->orWhereHas('user.contact', function ($query) use ($id) {
$query->where('user_id', '=', $id);
})->orWhere('user_id','=',$id);
});
$eventrecommended = $eventrecommended->Where(function($query1) use($id){
$query1->where('public','=', 1)->orWhereHas('user.contact', function ($query) use ($id) {
$query->where('user_id', '=', $id);
})->orWhere('user_id','=',$id);
});
}
}
else{
$event = $event->where('public','=', 1);
$eventrecommended = $eventrecommended->where('public','=', 1);
}
return view('event.view_all_event',$data);
}
And in the second photo is my noticeboard, which I have same problem...
Add to your $event in your controller
where('active', 0)
and delete the if statment in your view
#if($event->active != 1)
#endif

Limit latest news usinf foreach

How Can I set a limit for "Recent News" posts? I wanted to set a limit for 4, but it's showing all of them. As a bonus insert a "SEE ALL NEWS" button in the end...
I have this:
#foreach($news as $news)
#php
$news_img = ($news['anexo'] ? get_image_small_url($news['anexo']['ane_arquivo']) : '');
$news_img = $news_img ?: 'http://placehold.it/300.jpg?text=%20';
$news_txt = (empty($news['pub_resumo']) ? $news['pub_conteudo'] : $news['pub_resumo']);
#endphp
<div class="media media-thumb">
#if($news_img)
<div class="media-left">
<a href="{{ url('/news/'.$news['post_id']) }}">
<img class="media-object" src="{{ $news_img }}" alt="{{ $news['pub_titulo'] }}">
</a>
</div>
#endif
<div class="media-body">
<div class="post-meta">
<span class="published">{{ date('d/m/Y', strtotime($news['pub_data_cadastro'])) }}</span>
#if(!empty($news['categories']))
<span class="categories">{{ join(', ', array_column($news['categories'], 'tcp_nome')) }}</span>
#endif
</div>
<h4 class="media-heading">
{{ $news['title'] }}
</h4>
<p>{{ get_excerpt($news_txt, 180) }}</p>
</div>
</div>
#endforeach
The controller
$news = Publicacao::select('publicacao_id', 'pub_titulo', 'pub_conteudo', 'pub_resumo', 'pub_data_cadastro', 'anexo_id')
->with(['categorias', 'anexo'])
->where('pub_tipo', 'NOT')
->where('pub_status', 'PUB')
->limit(5)
->orderBy('pub_data_cadastro', 'desc')
->get();
$this->data['news'] = $news->toArray();
return view('site.home', $this->data);
}
Cheers!

get data from clicked div in laravel 4.2

hi i have this set of div for looped which contains data from the database here is how it looks like
here is my code to generate these divs
#foreach($NSAdata as $list)
{{ Session::put('isList' , 'true')}}
<div class="divcont">
<p>Filename : {{$list->filename}}</p>
<span>Size : {{$list->filesize}}</span>
#if($list->filetype == 'ppt' || $list->filetype == 'pptx')
<img src="{{ asset('img/ico/pptico.PNG') }}" class="imgicoII">
#elseif($list->filetype == 'doc' || $list->filetype == 'docx')
<img src="{{ asset('img/ico/wordico.PNG') }}" class="imgicoII">
#elseif($list->filetype == 'pdf')
<img src="{{ asset('img/ico/pdfico.PNG') }}" class="imgicoII">
#elseif($list->filetype == 'xls' || $list->filetype == 'xlsx')
<img src="{{ asset('img/ico/excelico.PNG') }}" class="imgicoII">
#elseif($list->filetype == 'txt')
<img src="{{ asset('img/ico/txtico.png') }}" class="imgicoII">
#elseif($list->filetype == 'csv')
<img src="{{ asset('img/ico/csvico.PNG') }}" class="imgicoII">
#endif
<br>
#if($list->thumbnail != 'n/a')
<img src="{{ asset('uploads/docs/thumb/' . $list->thumbnail ) }}" class="imgicoIII">
#else
<img src="{{ asset('uploads/docs/thumb/noThumb.png' ) }}" class="imgicoIII">
#endif
<br>
<a class="modal-trigger z-depth-1 btn dgray " href="#modFile">
Edit
</a>
<a href="{{URL::route('openfile', array($list->fileid))}}" class="btn dgray">
View
</a>
</div>
#endforeach
when the user clicked the edit button i trigger a modal with an id of modFile, it is supposed to display a modal where it contains the data from the clicked div im able to display the modal but im not displaying the correct data. here is my code for the modal
<div id="modFile" class="modal modal1size">
<div id="modal-header" class="z-depth-2 blue lighten-1">
</div>
<div class="modal-content">
<div class="row rowMarg">
<h6>Information.</h6>
#if(Session::has('isList'))
<h6>Filename : {{ $list->filename }} </h6>
<h6>File type : {{ $list->filetype }} </h6>
<?php $extension = "";?>
#if($extension == 'ppt' || $extension == 'pptx')
<img src="{{ asset('img/ico/pptico.PNG') }}" class="imgico">
#elseif($extension == 'doc' || $extension == 'docx')
<img src="{{ asset('img/ico/wordico.PNG') }}" class="imgico">
#endif
<h6>Size : {{ $list->filesize }} </h6>
<br>
#endif
</div>
</div>
<div class="modal-footer grey lighten-4">
<button type="submit" class="waves-effect waves-darkblue-1 btn-flat buttoninset">Submit</button>
Cancel
</div>
the thing is it just display wrong info any idea what i am doing wrong or how can i improve my code?

Categories