app/Http/Controllers/OtController.php
/**
   * Display a listing of the resource.
   *
   * @return \Illuminate\Http\Response
   */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function datatable_index(Request $request)
   {
      $output= array();
      $ots= Ot::orderBy('created_at', 'ASC')->get();
      $fee= $request->fee;
      $f_inicio = '';
      $f_final = '';
      if ($request->has('f_inicio')) {
         $f_inicio = $request->get('f_inicio');
      }else{
         $f_inicio = null;
      }
      if ($request->has('f_final')) {
         $f_final = $request->get('f_final');
      }else{
         $f_final = null;
      }
      if ($request->has('fee') && $fee !='all' && $f_inicio != null && $f_final != null ) {
         $ots = Ot::with('cliente','usuario','estado')->where('estado',1)->where('fecha_inicio', '>=', $f_inicio)->where('fecha_inicio', '<=', $f_final)->where('fee', $fee )->get();
      }else if ($f_inicio != null && $f_final != null){
         $ots = Ot::with('cliente','usuario','estado')->where('estado',1)->where('fecha_inicio', '>=', $f_inicio)->where('fecha_inicio', '<=', $f_final)->get();
      }else if ($request->has('fee') && $fee !='all' ){
         $ots = Ot::with('cliente','usuario','estado')->where('estado',1)->where('fee', $fee )->get();
      }else{
         $ots = Ot::with('cliente','usuario','estado')->where('estado',1)->get();
      }
      $output = collect($ots);
      return Datatables::of($output)
      ->addColumn('select', function($ots) {
        return'<div class="checkbox_ots"><div class=" <!--checkbox checkbox-success permisos_check -->" >
             <input  class="styled"  type="checkbox" id="check_'.$ots->id.'"  value="'.$ots->id.'" >
            <!-- <label  for="check_'.$ots->id.'"></label>-->
        </div></div>';
      })
      ->addColumn('fecha_inicio', function($ots) {
         return  $ots->getFormatFecha($ots->fecha_inicio);
      })
      ->addColumn('fecha_final', function($ots) {
         return $ots->getFormatFecha($ots->fecha_final);
      })
      ->addColumn('acciones', function($ots) {
         $ver_ot='<a href="visualizar/'.$ots->id.'" class="btn_accion estado-2-10 btn-success"  title="Ver Ot" aria-label="View"><i class="fa fa-eye" aria-hidden="true"></i></a>';
         $editar_ot=(Auth::user()->can('editar_ots') )?'<a href="editar/'.$ots->id.'" title="Editar Ot"  class="btn_accion btn-info" aria-label="View"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>':'';
         $exportar_ot=(Auth::user()->can('editar_ots') )?'<a href="exportar/'.$ots->id.'" title="Exportar Ot"  class="btn_accion estado-2-10" aria-label="View"><i class="fa fa-file-excel-o" aria-hidden="true"></i></a>':'';
         $eliminar_ot=(Auth::user()->can('editar_ots') )?'<a href="#" id="cli-'.$ots->id.'" title="Eliminar Ot"  class="btn_accion delete_cliente btn-danger"  data-toggle="modal" data-target="#myModal"><i class="fa fa-trash-o" aria-hidden="true"></i></a>':'';
         $duplicar_ot=(Auth::user()->can('crear_ots') && $ots->fee == 1 )?'<a href="duplicar/'.$ots->id.'" title="Duplicar Ot"  class="btn_accion btn-warning" aria-label="Duplicar"><i class="fa fa-files-o" aria-hidden="true"></i></a>':'';
         return $ver_ot.$editar_ot.$exportar_ot.$eliminar_ot.$duplicar_ot;
      })
      ->make(true);
   }
public function datatable_index ( Request $ request ) { $ output = array ( ) ; $ ots = Ot :: orderBy ( 'created_at' , 'ASC' ) -> get ( ) ; $ fee = $ request -> fee ; $ f_inicio = '' ; $ f_final = '' ; if ( $ request -> has ( 'f_inicio' ) ) { $ f_inicio = $ request -> get ( 'f_inicio' ) ; } else { $ f_inicio = null ; } if ( $ request -> has ( 'f_final' ) ) { $ f_final = $ request -> get ( 'f_final' ) ; } else { $ f_final = null ; } if ( $ request -> has ( 'fee' ) && $ fee != 'all' && $ f_inicio != null && $ f_final != null ) { $ ots = Ot :: with ( 'cliente' , 'usuario' , 'estado' ) -> where ( 'estado' , 1 ) -> where ( 'fecha_inicio' , '>=' , $ f_inicio ) -> where ( 'fecha_inicio' , '<=' , $ f_final ) -> where ( 'fee' , $ fee ) -> get ( ) ; } else if ( $ f_inicio != null && $ f_final != null ) { $ ots = Ot :: with ( 'cliente' , 'usuario' , 'estado' ) -> where ( 'estado' , 1 ) -> where ( 'fecha_inicio' , '>=' , $ f_inicio ) -> where ( 'fecha_inicio' , '<=' , $ f_final ) -> get ( ) ; } else if ( $ request -> has ( 'fee' ) && $ fee != 'all' ) { $ ots = Ot :: with ( 'cliente' , 'usuario' , 'estado' ) -> where ( 'estado' , 1 ) -> where ( 'fee' , $ fee ) -> get ( ) ; } else { $ ots = Ot :: with ( 'cliente' , 'usuario' , 'estado' ) -> where ( 'estado' , 1 ) -> get ( ) ; } $ output = collect ( $ ots ) ; return Datatables :: of ( $ output ) -> addColumn ( 'select' , function ( $ ots ) { return '<div class="checkbox_ots"><div class=" <!--checkbox checkbox-success permisos_check -->" >
             <input  class="styled"  type="checkbox" id="check_' . $ ots -> id . '"  value="' . $ ots -> id . '" >
            <!-- <label  for="check_' . $ ots -> id . '"></label>-->
        </div></div>' ; } ) -> addColumn ( 'fecha_inicio' , function ( $ ots ) { return $ ots -> getFormatFecha ( $ ots -> fecha_inicio ) ; } ) -> addColumn ( 'fecha_final' , function ( $ ots ) { return $ ots -> getFormatFecha ( $ ots -> fecha_final ) ; } ) -> addColumn ( 'acciones' , function ( $ ots ) { $ ver_ot = '<a href="visualizar/' . $ ots -> id . '" class="btn_accion estado-2-10 btn-success"  title="Ver Ot" aria-label="View"><i class="fa fa-eye" aria-hidden="true"></i></a>' ; $ editar_ot = ( Auth :: user ( ) -> can ( 'editar_ots' ) ) ? '<a href="editar/' . $ ots -> id . '" title="Editar Ot"  class="btn_accion btn-info" aria-label="View"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>' : '' ; $ exportar_ot = ( Auth :: user ( ) -> can ( 'editar_ots' ) ) ? '<a href="exportar/' . $ ots -> id . '" title="Exportar Ot"  class="btn_accion estado-2-10" aria-label="View"><i class="fa fa-file-excel-o" aria-hidden="true"></i></a>' : '' ; $ eliminar_ot = ( Auth :: user ( ) -> can ( 'editar_ots' ) ) ? '<a href="#" id="cli-' . $ ots -> id . '" title="Eliminar Ot"  class="btn_accion delete_cliente btn-danger"  data-toggle="modal" data-target="#myModal"><i class="fa fa-trash-o" aria-hidden="true"></i></a>' : '' ; $ duplicar_ot = ( Auth :: user ( ) -> can ( 'crear_ots' ) && $ ots -> fee == 1 ) ? '<a href="duplicar/' . $ ots -> id . '" title="Duplicar Ot"  class="btn_accion btn-warning" aria-label="Duplicar"><i class="fa fa-files-o" aria-hidden="true"></i></a>' : '' ; return $ ver_ot . $ editar_ot . $ exportar_ot . $ eliminar_ot . $ duplicar_ot ; } ) -> make ( true ) ; }
Display a listing of the resource.
Display a listing of the resource .