2016-08-14 6 views
0

データベースからフェッチされたレコードをその値に基づいて非表示にしようとしています。値が0または1であれば、値1のレコードをすべて表示します私はYrara/DatatablesでLaravel 5.2を使用しています。データベース値に基づいてデータテーブルからレコードを非表示0/1

これは私のコントローラである:

public function get() { 
    if(!access()->allow('customers.read')) { 
     return redirect()->route('admin.dashboard')->withFlashDanger(trans('customers.general.messages.denied')); 
    } else { 
     $customers = Customer::select(array(
      'id', 'code', 'name', 'rnc', 'ced', 'phone', 'email', 'active' 
     )); 

     return Datatables::of($customers->get('status'), $customers->get('trashed')) 
      ->addColumn('actions', function($customers) { 
       return $customers->action_buttons; 

      })->addColumn('check', '<input type="checkbox" name="selected_users[]" value="{{ $id }}">') 
      ->make(true); 
    } 
} 

は、これが私の見解です:私の見解イムで

@extends('backend.layouts.master') 

@section('title', app_name() . ' | ' . trans('customers.general.customers_title')) 

@section('after-styles-end') 
{{ Html::style("css/backend/plugin/datatables/dataTables.bootstrap.min.css") }} 
@stop 

@section('page-header') 
    <h1> 
     {{ trans('customers.general.customers_title') }} <small>- {{ trans('customers.general.general') }}</small> 
    </h1> 
@endsection 

@section('content') 
    <div class="box box-success"> 
    <div class="box-header with-border"> 
     <h3 class="box-title">{{ trans('customers.general.customers_list') }}</h3> 
     <div class="box-tools pull-right"> 
      <a href="{{ route('admin.customers.create') }}" class="btn btn-sm btn-primary">{{ trans('customers.general.buttons.new_customer') }}</a> 
     </div> 
    </div><!-- /.box-header --> 
    <!-- Begins Customers Page --> 
    <div class="box-body"> 
     <div class="table-responsive"> 
      <table id="customers-table" class="table table-condensed table-hover"> 
       <thead> 
       <tr> 
        <th><input type="checkbox" name="select_all" value="1" id="example-select-all"></th> 
        <th class="">{{ trans('customers.general.table.code') }}</th> 
        <th class="">{{ trans('customers.general.table.business_name') }}</th> 
        <th class="">{{ trans('customers.general.table.document') }}</th> 
        <th class="">{{ trans('customers.general.table.phone') }}</th> 
        <th class="">{{ trans('customers.general.buttons.email') }}</th> 
        <th>{{ trans('labels.general.actions') }}</th> 
       </tr> 
       </thead> 
      </table> 
     </div><!--table-responsive--> 
    </div><!-- /.box-body --> 
</div><!--box--> 
@endsection 

@section('after-scripts-end') 
{{ Html::script("js/backend/plugin/datatables/jquery.dataTables.min.js") }} 
{{ Html::script("js/backend/plugin/datatables/dataTables.bootstrap.min.js") }} 
<script> 
    $(document).ready(function() { 
     var table = $('#customers-table').DataTable({ 
      processing: true, 
      serverSide: true, 
      ajax: { 
       url: '{{ route("admin.customers.get") }}', 
       type: 'get', 
       data: {active: 1} 
      }, 
      columns: [ 
       {data: 'check', name: 'check', orderable: false, searchable: false}, 
       {data: 'code', name: 'code'}, 
       {data: 'name', name: 'name'}, 
       {data: 'rnc', name: 'rnc'}, 
       {data: 'phone', name: 'phone'}, 
       {data: 'email', name: 'email'}, 
       {data: 'actions', name: 'actions', orderable: false, searchable: false} 
      ], 
      'columnDefs': [{ 
       'targets': 0, 
       'searchable':false, 
       'orderable':false, 
       'className': 'dt-body-center', 
       'render': function (data, type, full, meta){ 
        return '<input type="checkbox" name="id[]" value="' + $('<div/>').text(data).html() + '">'; 
       } 
      }], 
      "iDisplayLength": 10, 
      "aLengthMenu": [ 
       [10, 20, 30, 60, -1], 
       [10, 20, 30, 60, "{{ trans('strings.backend.general.table.all') }}"] 
      ], 
      language: { 
       "sProcessing": "{{ trans('strings.backend.general.table.processing') }}", 
       "sSearchPlaceholder": "{{ trans('strings.backend.general.search_placeholder') }}", 
       "search": "", 
       "lengthMenu": "{{ trans('strings.backend.general.table.show') }} _MENU_ {{ trans('strings.backend.general.table.records_by_page') }}", 
       "zeroRecords": "{{ trans('strings.backend.general.table.no_results') }}", 
       "info": "{{ trans('strings.backend.general.table.showing_page') }} _PAGE_ {{ trans('strings.backend.general.table.of') }} _PAGES_", 
       "infoEmpty": "{{ trans('strings.backend.general.table.empty') }}", 
       "infoFiltered": "({{ trans('strings.backend.general.table.filtered_of') }} _MAX_ {{ trans('strings.backend.general.table.total_records') }})", 
       "sInfo": "{{ trans('strings.backend.general.table.showing_from') }} _START_ {{ trans('strings.backend.general.table.to') }} _END_ {{ trans('strings.backend.general.table.of') }} _TOTAL_ {{ trans('strings.backend.general.table.records') }}", 
       "paginate": { 
        "previous": "{{ trans('strings.backend.general.table.previous') }}", 
        "next": "{{ trans('strings.backend.general.table.next') }}" 
       } 
      }, 
      order: [[0, "asc"]], 
      searchDelay: 500 
     }); 
     // Handle click on "Select all" control 
     $('#example-select-all').on('click', function(){ 
      // Get all rows with search applied 
      var rows = table.rows({ 'search': 'applied' }).nodes(); 
      // Check/uncheck checkboxes for all rows in the table 
      $('input[type="checkbox"]', rows).prop('checked', this.checked); 
     }); 

     // Handle click on checkbox to set state of "Select all" control 
     $('#example tbody').on('change', 'input[type="checkbox"]', function(){ 
      // If checkbox is not checked 
      if(!this.checked){ 
       var el = $('#example-select-all').get(0); 
       // If "Select all" control is checked and has 'indeterminate' property 
       if(el && el.checked && ('indeterminate' in el)){ 
        // Set visual state of "Select all" control 
        // as 'indeterminate' 
        el.indeterminate = true; 
       } 
      } 
     }); 

     // Handle form submission event 
     $('#frm-example').on('submit', function(e){ 
      var form = this; 

      // Iterate over all checkboxes in the table 
      table.$('input[type="checkbox"]').each(function(){ 
       // If checkbox doesn't exist in DOM 
       if(!$.contains(document, this)){ 
        // If checkbox is checked 
        if(this.checked){ 
         // Create a hidden element 
         $(form).append(
           $('<input>') 
             .attr('type', 'hidden') 
             .attr('name', this.name) 
             .val(this.value) 
         ); 
        } 
       } 
      }); 
     }); 
    }); 
</script> 
@stop 

すべての結果をretreivingが、そのも私が値1で無効にしているものを示し、私はちょうどリストに値0のものを表示したい、任意のヘルプは本当に感謝されるだろう。

おかげで、すべての

答えて

2

あなたのモデル内のスコープまたはグローバルスコープを使用することができますので、それらのレコードがまったく取得されません。お使いのモデルで :

public function apply(Builder $builder, Model $model) 
    { 
     return $builder->where('parameter', 1); 
    } 

このパラメータが= 1

+0

優れたレコードのみが返されます!完璧に働いた!おかげでミーナ –

+0

うれしい –

関連する問題