I have three tables. First is user which has an 'email' as a username. Second is customer which alos has email column. And third table is shipments. The shipment has relationship with customer table. User can login with email id which is present in User and Customer table. When user is logged in with their email I wamt to show shipments related to respective user, filterdered by email address of current logged in user. Please guide be. below is my index.blade.php
#extends('layouts.app')
#section('content')
<div class="page-titles">
<h2> Vishal {{ $pageTitle }} <small> {{ $pageNote }} </small></h2>
<h4></h4>
</div>
<div class="card">
<div class="card-body">
<div class="toolbar-nav" >
<div class="row">
<div class="col-md-4 col-4">
<div class="input-group ">
<input type="text" class="form-control form-control-sm onsearch" data-target="{{ url($pageModule) }}" aria-label="..." placeholder=" Type And Hit Enter ">
</div>
</div>
<div class="col-md-8 col-8 text-right">
<div class="btn-group">
#if($access['is_add'] ==1)
<a href="{{ url('shipments/create?return='.$return) }}" class="btn btn-sm btn-primary"
title="{{ __('core.btn_create') }}"><i class="fas fa-plus"></i> {{ __('core.btn_create') }}</a>
#endif
<div class="btn-group">
<button type="button" class="btn btn-sm btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fas fa-bars"></i> Bulk Action </button>
<ul class="dropdown-menu">
#if($access['is_remove'] ==1)
<li class="nav-item"><a href="javascript://ajax" onclick="SximoDelete();" class="nav-link tips" title="{{ __('core.btn_remove') }}">
Remove Selected </a></li>
#endif
#if($access['is_add'] ==1)
<li class="nav-item"><a href="javascript://ajax" class=" copy nav-link " title="Copy" > Copy selected</a></li>
<div class="dropdown-divider"></div>
<li class="nav-item"> Import CSV</li>
#endif
<div class="dropdown-divider"></div>
#if($access['is_excel'] ==1)
<li class="nav-item"> Export Excel </li>
#endif
#if($access['is_csv'] ==1)
<li class="nav-item"> Export CSV </li>
#endif
#if($access['is_pdf'] ==1)
<li class="nav-item"> Export PDF </li>
#endif
#if($access['is_print'] ==1)
<li class="nav-item"> Print Document </li>
#endif
<div class="dropdown-divider"></div>
<li class="nav-item"> Clear Search </li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!-- Table Grid -->
{!! Form::open(array('url'=>'shipments?'.$return, 'class'=>'form-horizontal m-t' ,'id' =>'SximoTable' )) !!}
<div class="table-responsive">
<table class="table table-hover table-striped " id="{{ $pageModule }}Table">
<thead>
<tr>
<th style="width: 3% !important;" class="number"> No </th>
<th style="width: 3% !important;">
<input type="checkbox" class="checkall filled-in" id="checked-all" />
<label for="checked-all"></label>
</th>
#foreach ($tableGrid as $t)
#if($t['view'] =='1')
<?php $limited = isset($t['limited']) ? $t['limited'] :'';
if(SiteHelpers::filterColumn($limited ))
{
$addClass='class="tbl-sorting" ';
if($insort ==$t['field'])
{
$dir_order = ($inorder =='desc' ? 'sort-desc' : 'sort-asc');
$addClass='class="tbl-sorting '.$dir_order.'" ';
}
echo '<th align="'.$t['align'].'" '.$addClass.' width="'.$t['width'].'">'.\SiteHelpers::activeLang($t['label'],(isset($t['language'])? $t['language'] : array())).'</th>';
}
?>
#endif
#endforeach
<th style="width: 10% !important;">{{ __('core.btn_action') }}</th>
</tr>
</thead>
<tbody>
#foreach ($rowData as $row)
<tr>
<td class="thead"> {{ ++$i }} </td>
<td class="tcheckbox">
<input type="checkbox" class="ids filled-in" name="ids[]" value="{{ $row->id }}" id="val-{{ $row->id }}" />
<label for="val-{{ $row->id }}"></label>
</td>
#foreach ($tableGrid as $field)
#if($field['view'] =='1')
<?php $limited = isset($field['limited']) ? $field['limited'] :''; ?>
#if(SiteHelpers::filterColumn($limited ))
<?php $addClass= ($insort ==$field['field'] ? 'class="tbl-sorting-active" ' : ''); ?>
<td align="{{ $field['align'] }}" width=" {{ $field['width'] }}" {!! $addClass !!} >
{!! SiteHelpers::formatRows($row->{$field['field']},$field ,$row ) !!}
</td>
#endif
#endif
#endforeach
<td>
<div class="dropdown">
<button class="btn dropdown-toggle" type="button" data-toggle="dropdown"><i class="fas fa-tasks"></i> </button>
<ul class="dropdown-menu">
#if($access['is_detail'] ==1)
<li class="nav-item"> {{ __('core.btn_view') }} </li>
#endif
#if($access['is_edit'] ==1)
<li class="nav-item"> {{ __('core.btn_edit') }} </li>
#endif
<div class="dropdown-divider"></div>
#if($access['is_remove'] ==1)
<li class="nav-item"><a href="javascript://ajax" onclick="SximoDelete();" class="nav-link tips" title="{{ __('core.btn_remove') }}">
Remove Selected </a></li>
#endif
</ul>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<input type="hidden" name="action_task" value="" />
{!! Form::close() !!}
<!-- End Table Grid -->
</div>
#include('footer')
</div>
</div>
<script>
$(document).ready(function(){
$('.copy').click(function() {
var total = $('input[class="ids"]:checkbox:checked').length;
if(confirm('are u sure Copy selected rows ?'))
{
$('input[name="action_task"]').val('copy');
$('#SximoTable').submit();// do the rest here
}
})
});
</script>
#stop
So you want to display shipments of a logged-in user? Then at this point, I'm expecting that you have already defined the Eloquent Relationships as methods on your Eloquent User and Shipment model classes and actually able to save the data.
In your Controller
use Illuminate\Support\Facades\Auth;
public function index()
{
$user = Auth::user()->load('shipments');
return view('sample.index', ['user' => $user]);
}
With the Auth::user() it checks if the current user is authenticated (returns true if the user is logged-in) via the Auth facade. Since the User model has already been retrieved, you can use Lazy Eager Loading with the load() to load the Shipment model.
And in your blade, you can display user's info and iterate over the shipment collection like so:
#foreach ($user->shipments as $shipment)
<p>{{ $shipment->field }}</p>
#endforeach
Related
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 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!!!!
This is my first big project with Laravel. I added a multirow delete function for my users table, it worked and logged me off and I haven't been able to log in again. Also all my routes aren't working.
i'm not really certain on what to do, i've tried to log in with other user details but the result is still the same. I've created a new user profile too.
Below is the code on the user blade file
#extends('layouts.admin')
#section('content')
<!-- Page Heading -->
#can('user_create')
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h2 class="h3 mb-0 ">Staff</h2>
<span class="d-md-flex d-sm-block left-side ">
Add Staff
</span>
</div>
#endcan
<!-- toolbar -->
<div class="row">
<div class="col-2">
<div class="d-md-flex">
<span class="d-flex mr-4">
<span class="mr-2"><small>Sort</small></span> <div class="dropdown arrow">
<a class="dropdown-toggle font-weight-bold" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<small>All</small>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="#">Name</a>
<a class="dropdown-item" href="#">No of ticket</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</span>
<span>
Layout off Staff
</span>
</div>
</div>
</div>
<div class="row">
<!-- main content column -->
<div class="col-xl-12 col-lg-12">
<div class="table-responsive px-1">
<table class="ajaxTable datatable datatable-User">
<thead>
<tr>
<th scope="col ml-3"><small class="align-middle">
<label class="checkbox-container">
<input type="checkbox" id="chkCheckAll">
<span class="checkmark"></span>
</label>
</th>
<th scope="col ml-3 "><small class="align-middle">Name <small></th>
<th scope="col ml-3"><small class="align-middle">Position<small></th>
<th scope="col ml-3"><small class="">Department<small></th>
<th scope="col ml-3"><small class="">Phone<small></th>
<th scope="col ml-3"><small class="">Email<small></th>
<th scope="col ml-3"><small class="">Assigned ticket<small></th>
<th scope="col ml-3"><small class="">Date Created<small></th>
<th scope="col ml-3"><small class="">Actions<small></th>
</tr>
</thead>
<tbody>
#foreach($users as $key => $user)
<tr class="rounded-3" id="sid{{ $user->id }}">
<td class="align-middle">
<label class="checkbox-container">
<input type="checkbox" name="ids" value="{{ $user->id }}" class="chkBoxClass" >
<span class="checkmark"></span>
</label>
</td>
<td>
<a href="{{ route("admin.users.show",$user) }}"><span class="d-block font-weight-bold">
<img class="img-profile rounded-circle mr-2" height ="40" width="40" src="https://source.unsplash.com/QAB-WJcbgJk/60x60">
{{ $user->name ?? '' }}</span></a>
</td>
<td>
#foreach($user->roles as $key => $item)
<span class="badge badge-info">{{ $item->title }}</span>
#endforeach
</td>
<td class="align-middle">
#foreach($user->categories as $key => $item)
<div>{{ $item->name }}</div>
#endforeach
</td>
<td class="align-middle">
{{ $user->phone}}
</td>
<td class="align-middle font-weight-bold">
{{ $user->email ?? '' }}
</td>
<td class="align-middle">
{{ count($user->tickets) }}
</td>
<td class="align-middle text-center">
{{ $user->created_at ?? '' }}
</td>
<td>
<div class="dropdown no-arrow">
<a class="dropdown-toggle font-weight-bold" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400 "></i>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
#can('user_show')
<a class="dropdown-item" href="{{ route('admin.users.show', $user->id) }}">
{{ trans('global.view') }}
</a>
#endcan
#can('user_edit')
<a class="dropdown-item" href="{{ route('admin.users.edit', $user->id) }}">
{{ trans('global.edit') }}
</a>
#endcan
#can('user_delete')
<form class="d-flex" action="{{ route('admin.users.destroy', $user->id) }}" method="POST" onsubmit="return confirm('{{ trans('global.areYouSure') }}');" style="display: inline-block;">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" class="dropdown-item" value="{{ trans('global.delete') }}">
</form>
#endcan
</div>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
{{ $users->links() }}
</div>
</div>
</div>
#endsection
#section('scripts')
#parent
<script>
$(function ()
{
let dtButtons = $.extend(true, [], $.fn.dataTable.defaults.buttons)
#can('user_delete')
let deleteButtonTrans = '{{ trans('global.datatables.delete') }}'
let deleteButton = {
text: deleteButtonTrans,
url: "{{ route('admin.users.massDestroy') }}",
className: 'btn-danger',
action: function (e, dt, node, config) {
var ids = $.map(dt.rows({ selected: true }).nodes(), function (entry) {
return $(entry).data('entry-id')
});
if (ids.length === 0) {
alert('{{ trans('global.datatables.zero_selected') }}')
return
}
if (confirm('{{ trans('global.areYouSure') }}')) {
$.ajax({
headers: {'x-csrf-token': _token},
method: 'POST',
url: config.url,
data: { ids: ids, _method: 'DELETE' }})
.done(function () { location.reload() })
}
}
}
dtButtons.push(deleteButton)
#endcan
$.extend(true, $.fn.dataTable.defaults, {
order: [[ 1, 'desc' ]],
pageLength: 4,
});
$('.datatable-User:not(.ajaxTable)').DataTable({ buttons: dtButtons })
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e){
$($.fn.dataTable.tables(true)).DataTable()
.columns.adjust();
});
})
</script>
<script>
$(function(e){
$("#chkCheckAll").click(function(){
$(".chkBoxClass").prop('checked', $(this).prop('checked'));
});
$('#DASR').click(function(e){
e.preventDefault();
var allids = [];
$("input:checkbox[name=ids]:checked").each(function(){
allids.push($(this).val());
});
$.ajax({
url:"{{route('admin.users.massDestroy')}}",
type:'DELETE',
data:{
ids:allids,
_token: $("input[name=_token]").val()
},
success:function(response)
{
$.each(allids,function(key, val){
$('#sid'+val).remove();
});
}
});
});
});
</script>
#endsection
Do you have a repo to share so we can see the full code base. I would say the problem is not to do with this page exactly. Would be interesting to know what the functionality is behind the route 'admin.users.massDestroy' too... this may have deleted something it should not have done.
Other than that I can only take a guess and possibly say the passwords aren't correct when logging in. Or something wrong with the cache. You could try clearing it.
I'm so confused why i can't export this to excel. Please help me. Theres an error where it can't read "all".
Here's my code in my UsersController
public function userExport()
{
Excel::create('data_function',function($excel){
$excel->sheet('mysheet', function($sheet){
$sheet->loadView('user.list');
});
})->download('xls');
}
Then here is it in my user/list.blade
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Employees
<small>#lang('app.list_of_registered_users') - {{ $all }}</small>
</h1>
</div>
</div>
#include('partials.messages')
<form method="GET" action="" accept-charset="UTF-8" id="users-form">
<div class="row tab-search">
<div class="col-md-2">
<div class="form-group-sm">
<select class="form-control form-control-sm" id="company" name="company">
<option selected disabled>Company</option>
#foreach ($companies as $company)
#if (($company->id)=="1")
<option>All</option>
#else
<option value="{{ $company->id }}">{{ $company->name }}</option>
#endif
#endforeach
</select>
</div>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-warning btn-sm btn-block" id="filter-user">
<i class="glyphicon glyphicon-filter"></i>
Filter Employee
</button>
</div>
<div class="col-md-1">
<a href="{{ route('user.export') }}" class="btn btn-sm btn-success btn-block">
<i class="fa fa-file-excel-o"></i>
Excel
</a>
</div>
<div class="col-md-2">
<a href="{{ route('user.create') }}" class="btn btn-primary btn-sm btn-block" id="add-user">
<i class="glyphicon glyphicon-plus"></i>
Add
Employee
</a>
</div>
</div>
<div class="row tab-search"> <div class="col-md-2">
<div class="form-group-sm">
<select class="form-control form-control-sm" id="benefit" name="benefit">
<option selected disabled>Benefits</option>
#foreach ($benefits as $benefit)
#if (($benefit->id)=="1")
<option>All</option>
#else
<option value="{{ $benefit->id }}">{{ $benefit->name }}</option>
#endif
#endforeach
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group-sm">
<div class="input-group custom-search-form-sm">
<input type="text" class="form-control form-control-sm" name="search" value="{{ Input::get('search') }}" placeholder="Search Name">
<span class="input-group-btn">
<button class="btn btn-default btn-sm" type="submit" id="search-users-btn">
<span class="glyphicon glyphicon-search"></span>
</button>
#if (Input::has('search') && Input::get('search') != '')
<a href="{{ route('user.list') }}" class="btn btn-danger btn-sm" type="button" >
<span class="glyphicon glyphicon-remove"></span>
</a>
#endif
</span>
</div>
</div>
</div>
</div>
</div>
</form>
<div class="table-responsive" id="users-table-wrapper">
<table class="table table-bordered table-striped table-hover table-condensed" id="datatable-default">
<thead>
<th>#lang('app.full_name')</th>
<th>Sex<i type="button" class="fa fa-fw fa-sort"></th>
<th>Birthday<button name="birthday_sort" style="background-color:#ffffff"><i class="fa fa-fw fa-sort"></button></th>
<th>Age<i class="fa fa-fw fa-sort"></th>
<th>Civil<br>Status<i class="fa fa-fw fa-sort"></th>
<th>Company<i class="fa fa-fw fa-sort"></th>
<th>Department<i class="fa fa-fw fa-sort"></th>
<th>Employee<br>Status<i class="fa fa-fw fa-sort"></th>
<th>Level<i class="fa fa-fw fa-sort"></th>
<th>Date<br>Hired<i class="fa fa-fw fa-sort"></th>
<th>Tenure</th>
</thead>
<tbody>
#if (count($users))
#foreach ($users as $user)
<tr class="gradeX">
<td>{{ $user->first_name . ' ' . $user->middle_name . ' ' . $user->last_name }}</td>
<td>{{ $user->gender[0] }}</td>
<td>{{ $user->birthday->format('M j/y') }}</td>
<td>{{ $user->age }}</td>
<td>{{ $user->civil_status }}</td>
<td>#foreach ($user->company as $company)#endforeach{{ $company->name }}</td>
<td>#foreach ($user->department as $department)#endforeach{{ $department->name }}</td>
<td>{{ $user->emp_status }}</td>
<td>{{ $user->level }}</td>
<td>{{ $user->date_hired }}</td>
<td>{{ $user->difference }}</td>
</tr>
#endforeach
#else
<tr class="gradeX">
<td colspan="6"><em>#lang('app.no_records_found')</em></td>
</tr>
#endif
</tbody>
</table>
{!! $users->render() !!}
</div>
The problem is that it says an error like "all","companies", and etc are undefined variables. Also because the companies is another table. How can define it in my excel that it won't be error again?
It seems you need to pass variables to view from controller which you are passing. Please check my code and update.
public function userExport()
{
$companies = $this->companyModel->get();
$all = $this->something->get();
Excel::create('data_function',function($excel) use($all, $companies) {
$excel->sheet('mysheet', function($sheet) use($all, $companies) {
$sheet->loadView('user.list', ['all' => $all, 'companies' => $companies]);
});
})->download('xls');
}
and also pass the other variables with same as I passed to $sheet->loadView() in example.
I think this will help you.
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