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');
});
I need to show nested notes if were exist into my table, I have worked it these way, it works only for first row, and I can't know what i did wrong.
this is my code:
<td>
#inject('Common', 'App\Http\Controllers\AuditYearController')
#if($Common->has_entry_note($entry->id) == 'true')
<ul id="treeview1">الملاحظات
#foreach($entry_notes=$Common->get_entry_notes($entry->id) as $es)
<li>{{ $es->text }}
<ul>
<li>{{ $es->suggestion }}</li>
<li>{{ $es->clarification }}</li>
</ul>
</li>
#endforeach
</ul>
#else
لا يوجد ملاحظات
#endif
</td>
and this is the result.
I solved it by using accordion.
<td>
#inject('Common', 'App\Http\Controllers\AuditYearController')
#if ($Common->has_entry_note($entry->id) == 'true')
#foreach ($entry_notes = $Common->get_entry_notes($entry->id) as $es)
<div class="accordion accordion-flush" id="e{{ $es->en_id }}">
<div class="accordion-item">
<h6 class="accordion-header" id="head{{ $es->en_id }}">
<a class="collapsed" type="button" data-toggle="collapse"
data-target="#one{{ $es->en_id }}" aria-expanded="true"
aria-controls="one{{ $es->en_id }}">
<i class="si si-plus text-teal"></i><strong>{{ $es->text }}</strong></a></h6>
<div id="one{{ $es->en_id }}" class="accordion-collapse collapse"
aria-labelledby="head{{ $es->en_id }}" data-parent="#e{{$es->en_id }}">
<div class="accordion-body">
{{ $es->suggestion }}
{{ $es->clarification }}
</div><br>
</div>
</div>
</div>
#endforeach
#else
لا يوجد ملاحظات
#endif
</td>
i am starting to create an ads site, i display 36 products in a blade index with success, my problem is that 36 of the products display, the leftovers do not display, and i don't know how to display the 2nd page and 3rd and so on depending on the number of pages to display the other products.
AnnoncesController.php
public function index()
{
$categories = Category::all();
$annonces = Annonce::paginate(36);
return view('annonces.index')->with([
'categories' => $categories,
'annonces' => $annonces,
]);
}
index.blade.php
<div class="row mix-grid thumbnails">
#foreach($annonces as $annonce)
<div class="col-md-3 col-xs-3 mix {{ $annonce->category->slug }} cat_all">
<a class="thumbnail-item">
<img src="{{ asset('storage/'.$annonce->image) }}" alt="category" />
</a>
<div class="thumbnail-data">
<h5>{{ $annonce->titre }}</h5>
<p>{{ substr($annonce->description, 0, 34) }}...</p>
<div class="thumbnail-info" align="center">
<button class="btn btn-primary"><span class="fa fa-edit"></span></button>
<button class="btn btn-primary"><span class="fa fa-trash-alt"></span></button>
<button class="btn btn-primary"><span class="fa fa-eye"></span></button>
</div>
</div>
</div>
#endforeach
</div>
<ul class="pagination pagination-sm pull-right">
<li class="disabled">«</li>
<li class="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>»</li>
</ul>
You can do like this
#if($annonces->hasPages())
{{ $annonces->links() }}
#endif
If you want custom pagination, save the following as a new blade file and add name to ->links() method as a parameter.
#if ($paginator->lastPage() > 1)
<ul class="pagination">
#if(($paginator->currentPage() > 1))
<li class="{{ ($paginator->currentPage() == 1) ? '' : '' }}">
<<
</li>
#endif
#for ($i = 1; $i <= $paginator->lastPage(); $i++)
<li class="{{ ($paginator->currentPage() == $i) ? 'current' : '' }}">
{{ $i }}
</li>
#endfor
#if(($paginator->currentPage() != $paginator->lastPage()))
<li class="{{ ($paginator->currentPage() == 1) ? '' : '' }}">
>>
</li>
#endif
</ul>
#endif
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);
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