@click :
About caching:
I have changed my UserController index method to:
public function index() {
if (!Auth::user()->can('users-general-access')) { return Redirect::to('zadania'); }
$users = Cache::rememberForever('users', function () {
return User::with('role')->get();
});
return view('osoby.index')->with([
'users' => $users,
]);
}
and I dont see any big difference beside reducing 6 queries to 3.
@Cronix :
Here is my index.blade.php view:
@section('width', 'fullwidth')
@extends('layouts.app')
@section('title', 'Osoby')
@section('submenu')
@include('osoby.partial.submenu')
@endsection
@section('modals')
@include('partial.modals.delete')
@endsection
@section('content')
@hasSection('width')
<section class="content container-fluid">
@else
<section class="content container">
@endif
<div class="row">
<div class="col-xs-12">
<h1 class="page-header">Osoby</h1>
</div>
<div class="col-xs-12">
@include('partial.errors')
@can('users-add')
<a class="btn" href="{!! URL::to('osoby/create') !!}">Dodaj osobę</a>
@endcan
<table id="main-table" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Imię i nazwisko</th>
<th>E-mail</th>
<th>Telefon</th>
<th>Zawieszony</th>
<th>Rola</th>
@canany('users-edit|users-delete|users-lock')<th></th>@endcanany
</tr>
</thead>
<tfoot>
<tr>
<th>Imię i nazwisko</th>
<th>E-mail</th>
<th>Telefon</th>
<th>Zawieszony</th>
<th>Rola</th>
@canany('users-edit|users-delete|users-lock')<th></th>@endcanany
</tr>
</tfoot>
<tbody>
@foreach($users as $key => $value)
<tr>
<td class="{{ $value->statusLock() }}"><a href="{{ URL::to('osoby/' . $value->id . '/edit') }}">{{ $value->fullName }}</a></td>
<td class="{{ $value->statusLock() }}">{{ $value->email }}</td>
<td class="{{ $value->statusLock() }}">{{ $value->phone }}</td>
<td class="{{ $value->statusLock() }}">{{ ($value->active) ? 'nie' : 'tak' }}</td>
<td class="{{ $value->statusLock() }}">
@if ($value->role)
{{ $value->role->label }}
@endif
</td>
@canany('users-edit|users-delete|users-lock')
<td class="nowrap">
@can('users-edit')
<a class="table-ico" href="{{ URL::to('osoby/' . $value->id . '/edit') }}"><img src="{{ URL::asset('img/ico-edit.png') }}" alt="" /></a>
@endcan
@can('users-delete')
<a class="table-ico modal-open modal-open-delete" data-modal="modal-delete-form" data-id="{{$value->id}}"><img src="{{ URL::asset('img/ico-delete.png') }}" alt="" /></a>
@endcan
@can('users-lock')
<a class="table-ico" href="{{ URL::to('osoby/' . $value->id . '/lock') }}" title="
@if($value->active == 1)
Zablokuj osobę (nie będzie mógł do czasu odblokowania logować się do systemu)
@else
Odblokuj osobę
@endif
"><img src="{{ URL::asset('img/ico-lock.png') }}" alt="" /></a>
@endcan
</td>
@endcanany
</tr>
@endforeach
</tbody>
</table>
<script>
$(document).ready(function() {
$('#main-table').dataTable({
"language": {
"processing": "Przetwarzanie...",
"search": "Szukaj:",
"lengthMenu": "Pokaż _MENU_ pozycji",
"info": "Pozycje od _START_ do _END_ z _TOTAL_ łącznie",
"infoEmpty": "Pozycji 0 z 0 dostępnych",
"infoFiltered": "(filtrowanie spośród _MAX_ dostępnych pozycji)",
"infoPostFix": "",
"loadingRecords": "Wczytywanie...",
"zeroRecords": "Nie znaleziono pasujących pozycji",
"emptyTable": "Brak danych",
"paginate": {
"first": "Pierwsza",
"previous": "Poprzednia",
"next": "Następna",
"last": "Ostatnia"
},
"aria": {
"sortAscending": ": aktywuj, by posortować kolumnę rosnąco",
"sortDescending": ": aktywuj, by posortować kolumnę malejąco"
}
},
"pageLength" : 100,
"order" : [[3, 'asc'], [4, 'desc']],
});
$('body').on('click', 'a.modal-open-delete', function() {
project_id = $(this).data("id");
action = '<?php echo URL::to('osoby'); ?>/'+project_id;
$('#delete-form').attr('action', action);
});
});
</script>
</div>
</div>
</section>
@endsection