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);
Related
I want to add my slider to my home page and when i add using #inclued method and it returns error undefended variable in slider page but it works well in slider page however i added it to home page error occurs. how do i correct this.
error msg-
Undefined variable $data (View: \resources\views\frontendslider.blade.php)
In the: \resources\views/frontendslider.blade.php file at line: 29
codes....
homepage
* LaraClassifier - Classified Ads Web Application
* Copyright (c) BeDigit. All Rights Reserved
*
* Website: https://laraclassifier.com
*
* LICENSE
* -------
* This software is furnished under a license and may be used and copied
* only in accordance with the terms of such license and with the inclusion
* of the above copyright notice. If you Purchased from CodeCanyon,
* Please read the full License from here - http://codecanyon.net/licenses/standard
--}}
#extends('layouts.master')
#section('search')
#parent
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.form', 'search.inc.form'])
#endsection
#section('content')
<div class="main-container">
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.breadcrumbs', 'search.inc.breadcrumbs'])
#if (config('settings.list.show_cats_in_top'))
#if (isset($cats) && $cats->count() > 0)
<div class="container mb-2 hide-xs">
<div class="row p-0 m-0">
<div class="col-12 p-0 m-0 border border-bottom-0 bg-light"></div>
</div>
</div>
#endif
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.categories', 'search.inc.categories'])
#endif
<?php if (isset($topAdvertising) && !empty($topAdvertising)): ?>
#includeFirst([config('larapen.core.customizedViewPath') . 'layouts.inc.advertising.top', 'layouts.inc.advertising.top'], ['paddingTopExists' => true])
<?php
$paddingTopExists = false;
else:
if (isset($paddingTopExists) && $paddingTopExists) {
$paddingTopExists = false;
}
endif;
?>
<div class="container">
<div class="row">
{{-- Sidebar --}}
#if (config('settings.list.left_sidebar'))
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.sidebar', 'search.inc.sidebar'])
<?php $contentColSm = 'col-md-9'; ?>
#else
<?php $contentColSm = 'col-md-12'; ?>
#endif
{{-- Content --}}
<div class="{{ $contentColSm }} page-content col-thin-left mb-4">
<div class="category-list {{ config('settings.list.display_mode', 'make-grid') }}{{ ($contentColSm == 'col-md-12') ? ' noSideBar' : '' }}">
<div class="tab-box">
{{-- Nav tabs --}}
<ul id="postType" class="nav nav-tabs add-tabs tablist" role="tablist">
<?php
$aClass = '';
$spanClass = 'alert-danger';
if (config('settings.single.show_listing_types')) {
if (!request()->filled('type') || request()->get('type') == '') {
$aClass = ' active';
$spanClass = 'bg-danger';
}
} else {
$aClass = ' active';
$spanClass = 'bg-danger';
}
?>
<li class="nav-item">
<a href="{!! qsUrl(request()->url(), request()->except(['page', 'type']), null, false) !!}" class="nav-link{{ $aClass }}">
{{ t('All Listings') }} <span class="badge badge-pill {!! $spanClass !!}">{{ $count->get('all') }}</span>
</a>
</li>
#if (config('settings.single.show_listing_types'))
#if (isset($postTypes) && $postTypes->count() > 0)
#foreach ($postTypes as $postType)
<?php
$postTypeUrl = qsUrl(
request()->url(),
array_merge(request()->except(['page']), ['type' => $postType->id]),
null,
false
);
$postTypeCount = ($count->has($postType->id)) ? $count->get($postType->id) : 0;
?>
#if (request()->filled('type') && request()->get('type') == $postType->id)
<li class="nav-item">
<a href="{!! $postTypeUrl !!}" class="nav-link active">
{{ $postType->name }}
<span class="badge badge-pill bg-danger">
{{ $postTypeCount }}
</span>
</a>
</li>
#else
<li class="nav-item">
<a href="{!! $postTypeUrl !!}" class="nav-link">
{{ $postType->name }}
<span class="badge badge-pill alert-danger">
{{ $postTypeCount }}
</span>
</a>
</li>
#endif
#endforeach
#endif
#endif
</ul>
<div class="tab-filter pb-2">
{{-- OrderBy Desktop --}}
<select id="orderBy" title="sort by" class="niceselecter select-sort-by small" data-style="btn-select" data-width="auto">
#if (isset($orderByArray) && !empty($orderByArray))
#foreach($orderByArray as $option)
#if ($option['condition'])
<option{{ $option['isSelected'] ? ' selected="selected"' : '' }} value="{!! $option['url'] !!}">
{{ $option['label'] }}
</option>
#endif
#endforeach
#endif
</select>
</div>
</div>
<div class="listing-filter">
<div class="float-start col-md-9 col-sm-8 col-12">
<h1 class="h6 pb-0 breadcrumb-list">
{!! (isset($htmlTitle)) ? $htmlTitle : '' !!}
</h1>
<div style="clear:both;"></div>
</div>
{{-- Display Modes --}}
#if (isset($posts) && $posts->count() > 0)
<?php $currDisplay = config('settings.list.display_mode'); ?>
<div class="float-end col-md-3 col-sm-4 col-12 text-end listing-view-action">
#if (isset($displayModesArray) && !empty($displayModesArray))
#foreach($displayModesArray as $displayMode => $value)
<span class="grid-view{{ ($currDisplay == $displayMode) ? ' active' : '' }}">
#if ($currDisplay == $displayMode)
<i class="fas fa-th-large"></i>
#else
<a href="{!! $value['url'] !!}">
<i class="{{ $value['icon'] }}"></i>
</a>
#endif
</span>
#endforeach
#endif
</div>
#endif
<div style="clear:both"></div>
</div>
{{-- Mobile Filter Bar --}}
<div class="mobile-filter-bar col-xl-12">
<ul class="list-unstyled list-inline no-margin no-padding">
#if (config('settings.list.left_sidebar'))
<li class="filter-toggle">
<a class=""><i class="fas fa-bars"></i> {{ t('Filters') }}</a>
</li>
#endif
<li>
{{-- OrderBy Mobile --}}
<div class="dropdown">
<a class="dropdown-toggle" data-bs-toggle="dropdown">{{ t('Sort by') }}</a>
<ul class="dropdown-menu">
#if (isset($orderByArray) && !empty($orderByArray))
#foreach($orderByArray as $option)
#if ($option['condition'])
<li>{{ $option['label'] }}</li>
#endif
#endforeach
#endif
</ul>
</div>
</li>
</ul>
</div>
<div class="menu-overly-mask"></div>
{{-- Mobile Filter bar End--}}
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="contentAll" role="tabpanel" aria-labelledby="tabAll">
<div id="postsList" class="category-list-wrapper posts-wrapper row no-margin">
<div class="slider">
#include('frontendslider')
</div>
#if (config('settings.list.display_mode') == 'make-list')
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.posts.template.list', 'search.inc.posts.template.list'])
#elseif (config('settings.list.display_mode') == 'make-compact')
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.posts.template.compact', 'search.inc.posts.template.compact'])
#else
#includeFirst([config('larapen.core.customizedViewPath') . 'search.inc.posts.template.grid', 'search.inc.posts.template.grid'])
#endif
</div>
</div>
</div>
<div class="tab-box save-search-bar text-center">
#if (request()->filled('q') && request()->get('q') != '' && $count->get('all') > 0)
<a id="saveSearch"
data-name="{!! qsUrl(request()->url(), request()->except(['_token', 'location']), null, false) !!}"
data-count="{{ $count->get('all') }}"
>
<i class="far fa-bell"></i> {{ t('Save Search') }}
</a>
#else
#endif
</div>
</div>
#if ($posts->hasPages())
<nav class="mt-3 mb-0 pagination-sm" aria-label="">
{!! $posts->appends(request()->query())->links() !!}
</nav>
#endif
</div>
</div>
</div>
{{-- Advertising --}}
#includeFirst([config('larapen.core.customizedViewPath') . 'layouts.inc.advertising.bottom', 'layouts.inc.advertising.bottom'])
{{-- Promo Listing Button --}}
<div class="container mb-3">
<div class="card border-light text-dark bg-light mb-3">
<div class="card-body text-center">
<h2>{{ t('do_you_have_anything') }}</h2>
<h5>{{ t('sell_products_and_services_online_for_free') }}</h5>
#if (!auth()->check() && config('settings.single.guests_can_post_listings') != '1')
{{ t('start_now') }}
#else
{{ t('start_now') }}
#endif
</div>
</div>
</div>
{{-- Category Description --}}
#if (isset($cat, $cat->description) && !empty($cat->description))
#if (!(bool)$cat->hide_description)
<div class="container mb-3">
<div class="card border-light text-dark bg-light mb-3">
<div class="card-body">
{!! $cat->description !!}
</div>
</div>
</div>
#endif
#endif
{{-- Show Posts Tags --}}
#if (config('settings.list.show_listings_tags'))
#if (isset($tags) && !empty($tags))
<div class="container">
<div class="card mb-3">
<div class="card-body">
<h2 class="card-title"><i class="fas fa-tags"></i> {{ t('Tags') }}:</h2>
#foreach($tags as $iTag)
<span class="d-inline-block border border-inverse bg-light rounded-1 py-1 px-2 my-1 me-1">
<a href="{{ \App\Helpers\UrlGen::tag($iTag) }}">
{{ $iTag }}
</a>
</span>
#endforeach
</div>
</div>
</div>
#endif
#endif
</div>
#endsection
#section('modal_location')
#includeFirst([config('larapen.core.customizedViewPath') . 'layouts.inc.modal.location', 'layouts.inc.modal.location'])
#endsection
#section('after_scripts')
<script>
$(document).ready(function () {
$('#postType a').click(function (e) {
e.preventDefault();
var goToUrl = $(this).attr('href');
redirect(goToUrl);
});
$('#orderBy').change(function () {
var goToUrl = $(this).val();
redirect(goToUrl);
});
});
</script>
#endsection
controller
public function frontendslider(Request $request){
$data=slider::all();
return view('frontendslider',compact('data'));
}
public function frontendslider2(Request $request){
$data=slider::all();
return view('return',compact('data'));
}
web.php
Route::get('frontendslider',[App\Http\Controllers\Admin\SliderController::class,'frontendslider']);
Route::get('return',[App\Http\Controllers\Admin\SliderController::class,'frontendslider2']);
Anyone face like this kind of issue specelly working with lara classifers use this before your importing page or page that content update..
#php
$data=DB::table('slider')->get();
#endphp
PLS note input your data to $data and table name!!!!
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 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']);
I made a delete multiple function, but I have some troubles with. When I select 2 checkboxes, and submit it but after that I'm redirected to url/article/delete/559 with null message at dd($article_id).
Here is my controller function:
public function deleteArticles (requ $request){
$article_id = $request['news_id'];
dd($article_id);
DB::table('contacts')
->whereIn('id', $article_id)
->delete();
return back();
}
public function delete($id)
{
$careerSolution = \App\Contact::find($id);
$careerSolution->delete();
return redirect(URL::previous());
}
Here is my routes
Route::get('article/delete/{id?}', 'ContactController#delete');
Route::post('noticeboard/{page?}', array('as' => 'noticeboard', 'uses' => 'ContactController#deleteArticles'));
Here is my view
<div id="my_contacts_grid" class="profile-edit tab-pane fade in active" style="background: none repeat scroll 0 0;">
<dl class="dl-horizontal">
<?php $count_user = 0; ?>
#foreach($users as $user)
#if($count_user == 0)
<div class="row margin-bottom-20">
#endif
<?php $count_user++; ?>
<form method="POST" action="{{ action ('ContactController#deleteArticles')}}">
{{csrf_field()}}
<div class="col-sm-6 sm-margin-bottom-20">
<div class="profile-blog" style="padding: 0px">
<img class=" noticeboard-profile-picture" src="{{ asset('thumbnail') }}/{{ $user->profile_picture }}" alt="" style="margin-left: 20px;margin-top: 15px;">
<div style="top: 35px;position: relative;right: 85px;margin-bottom:30px" class="name-location">
<ul class="list-unstyled col-xs-12" >
<li>
<strong style="display: inline-table !important">
<h3>#if($user->role[0]->slug == "individuals")
<i style="font-size: 13px;left: 60px;position: relative;top: 2px;" class="icon-user"></i>
#elseif($user->role[0]->slug =='organizations')
<i style="font-size: 13px;left: 60px;position: relative;top: 2px" class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
#endif<a style="font-size: 16px;left: 60px;position: relative;top: 2px" href="{{ url('') }}/{{ $user->username }}"> {{ $user->username }}</a></h3></strong>
<p style="right: 10px;position: relative;width: 110%">
<i style="padding: 5px" class="icon-real-estate-020 u-line-icon-pro"></i><strong style="display: inline-table !important;font-size: 13px">Location : </strong> {{ $user->country->country }} <span class="{{$user->country->flag}}"></span><br>
<i style="padding: 5px" class="icon-notebook fa-"></i><strong style="display: inline-table !important;font-size: 13px">Industry : </strong> {{ $user->industry->industry }}<br>
#if($user->role[0]->slug == "individuals")
#foreach($user->career_path as $career_path)
<i style="padding: 5px" class="icon-speedometer"></i><strong style="display: inline-table !important;font-size: 13px">Function : </strong> {{ $career_path->functions->function }}
#break;
#endforeach
#elseif($user->role[0]->slug =='organizations')
<i style="padding: 5px" class="icon-frame fa-"></i><strong style="display: inline-table !important;font-size: 13px">Organization : </strong> {{ $user->organization_type->organization_type }}<br>
#endif
</p>
</li>
</ul>
</div>
<hr>
<ul class="social-icons social-icons-color" style="display:none;">
<div class="social-cu" id="social-cu">
<li class="facebook_share" link="{{ url('') }}/{{ $user->username }}" style="left: 5px;position: relative">
<img id="social-im" class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/facebook-test.png') }}" alt="" style="height: 22px !important">
</li>
<li class="twitter_share" link="{{ url('') }}/{{ $user->username }}" name="{{ $user->username }} Workstickers Profile" style="left: 15px; position: relative">
<img id="social-im" class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/twitter-test.png') }}" alt="" style="height: 22px !important">
</li>
<li class="whatapp_share" link="{{ url('') }}/{{ $user->username }}" name="{{ $user->username }} Workstickers Profile" style="left: 25px;position: relative">
<a href="whatsapp://send?text={{ url('') }}/{{ $user->username }}" style="top: 5px; position: relative">
<img id="social-w" class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/Whatsapp.png') }}" style="height: 25px !important" alt="">
</a>
</li>
</div>
</ul>
<ul class="list-inline share-list" style="text-align: center;padding-bottom:10px">
<li>
<input name="news_id[]" type="checkbox" class="checkbox_news" value="{{$user->id}}"/>
</li>
<li>
<i class="fa fa-times"></i> Remove
</li>
<li class="send-contact-message " data-toggle="modal" data-target="#ssend_message_touser_{{ $user->id }}">
<i class="fa fa-paper-plane"></i>Send message
</li>
<li class="share-link">
<i class="fa fa-share-alt"></i> Share
</li>
</ul>
{!! Form::close() !!}
</div>
</div>
#if($count_user == 2)
</div>
<?php $count_user = 0; ?>
#endif
<!-- Modal -->
<div class="modal fade" id="ssend_message_touser_{{ $user->id }}" role="dialog" style="margin-top:40px;">
<div class="modal-dialog">
<!-- Modal email-->
<div class="modal-content" style="border-radius: 0px;top: 200px">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="mt-5">Send message to {{ $user->username }}</h4>
</div>
<div class="modal-body">
{!! Form::open(['class' => 'form-horizontal sky-form sky-changes-3','url' => 'message-send']) !!}
<div class="form-group" >
<label class="col-lg-2 control-label" style="display: none">To</label>
<div class="col-lg-10">
<input style="display: none" class="form-control" type="email" name="username" value="{{ $user->username }}" readonly>
<input class="form-control" type="hidden" name="contact_user_id" value="{{ $user->id }}">
<input class="form-control" type="hidden" name="url" value="{{ url('') }}/{{ $user->username }}">
</div>
</div>
<fieldset>
<section>
<label class="label">Subject</label>
<label class="input">
<i class="icon-append fa fa-tag"></i>
<input type="text" name="subject" id="subject">
</label>
</section>
<section>
<label class="label">Message</label>
<label class="textarea">
<i class="icon-append fa fa-comment"></i>
<textarea rows="4" name="message" id="message" ></textarea>
</label>
</section>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" style="bottom: 2px;position: relative">Close</button>
<button type="submit" class="btn-u btn-u-primary">Send message</button>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
<!-- end email Modal -->
#endforeach
<a href="{{ url('article/delete/'.$user->id) }}" role="button" class="btn btn-xs btn-danger" onclick="return confirm('Are you sure you want to delete this article?');">
<i class="fa fa-trash"></i>
</a>
</form>
{!! $users->render() !!}
</dl>
</div>
<style>
#social-cu{
width: 120px !important;
left: 200px;
top: -25px !important;
}
#social-im{
float: left;
width: 22px;
margin-right: 0px;
}
#social-w{
float: left;
width: 25px;
margin-right: 0px;
position: relative;
bottom: 3px;
}
</style>
<script type="text/javascript">
jQuery(document).ready(function() {
App.initScrollBar();
RegForm.initRegForm();
Datepicker.initDatepicker();
CheckoutForm.initCheckoutForm();
StyleSwitcher.initStyleSwitcher();
$(".send-contact-message").live('click', function(){
var user_id = $(this).attr('data-user-id');
$('#ssend_message_touser_'+user_id).modal('show');
});
});
</script>
<script type="text/javascript">
jQuery(document).ready(function() {
// StyleSwitcher.initStyleSwitcher();
$("#select_all").click(function () {
$(".checkbox_news").prop('checked',true);
});
$("#deselect_all").click(function () {
$(".checkbox_news").prop('checked',false);
});
});
</script>
So, when I check a checkbox or multiple, I should be able to have a multiple delete.
$careerSolution = \App\Contact::find($id);
When it's return null then you get error Call to a member function delete().
Use this One:
\App\Contact::where('id', $id)->delete();
I have this blade in my view. Right now, I have 6 blocks of them in my view because I'm not sure how to refactor it.
<div class="row filemanager">
<div class="col-sm-12">
#foreach ($devices as $device)
#if( $device->vlan_id == 100 AND $device->device_activity == 'ACTIVE' )
<div class="col-xs-6 col-sm-4 col-md-2 text-center">
<div class="thmb">
<div class="btn-group fm-group" style="display: none;">
<button type="button" class="btn btn-default dropdown-toggle fm-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu fm-menu" role="menu">
<li id="device-menu">
<a class="changeDeviceNameBtn" href="#"><i class="fa fa-pencil"></i> Change Device Name </a>
</li>
</ul>
</div>
<div class="thmb-prev">
<a href="/{{$cpe_mac}}/device/{{$device->device_mac}}">
#if(isset($device->device_name))
{{-- Show base on device name --}}
<img src="/images/photos/devices/{{img($device->device_name)}}.jpg" class="draggable img-responsive" alt="">
#else
{{-- No Device Name Set --}}
#if($device->hostname != '')
{{-- Show base on hostname --}}
<img src="/images/photos/devices/{{img($device->hostname)}}.jpg" class="draggable img-responsive" alt="">
#else
{{-- Show default --}}
<img src="/images/photos/devices/no-img.jpg" class="draggable img-responsive" alt="">
#endif
#endif
</a>
</div>
<h5 class="fm-title device_name">
<a href="/{{$cpe_mac}}/device/{{$device->device_mac}}">
#if($device->hostname == '')
No Devicename
#else
{{ $device->hostname}}
#endif
</a>
</h5>
<h5 class="text-muted device_ip">{{$device->ip_address}}</h5>
<h5 class="text-muted device_mac">{{$device->device_mac}}</h5>
<?php
$status = ucfirst(strtolower($device->device_activity));
if ($status == 'Active'){
$color = '#1CAF9A';
}else{
$color = '#D9534F';
}
?>
<h5>{{ $status }}
<i class="fa fa-circle" style="color:{{$color}}; margin-left: 7px;"></i>
</h5>
</div>
</div>
#endif
#endforeach
</div>
</div>
I want to make a function containing that blade, and only replace my
$device->vlan_id, and my $device->device_activity.
Example,
public static deviceRow(100,ACTIVE){
... my blade ...
}
Now, I just that function 6 times, rather than duplicate that block of code 6 times.
Is it even possible ?
Any hints / suggestions on this will be much appreciated !
You can make a partial with your blade and send a variable as a parameter:
In your parent view do something like this:
#foreach($somelist as $item)
#include('view.partial', ['name' => $item->name])
#endforeach
And in a file called partial.blade.php, do something like this:
{{ $device->$name }}
It's the main idea. Tell me if it helps...
You could create a new view and send some parameters with it while including:
#include('my.view', ['device' => $myDevice, 'activity' => 'ACTIVE'])
The keys of the array will be available as variables in your view.
The variable $myDevice would be available as $device in the view my.view