Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. //use Illuminate\Support\Facades\DB;
  7. use App\Factura;
  8.  
  9. class FacturaController extends Controller
  10. {
  11.     /**
  12.      * Display a listing of the resource.
  13.      *
  14.      * @return \Illuminate\Http\Response
  15.      */
  16.     public function index(Request $request)
  17.     {
  18.         if (!$request->ajax()) return redirect('/');
  19.  
  20.         $buscar = $request->buscar;
  21.         $criterio = $request->criterio;
  22.  
  23.         if ($buscar==''){
  24.             $facturas = Factura::orderBy('idfactura', 'desc')->paginate(4);
  25.         }
  26.         else{
  27.             $facturas = Factura::where($criterio, 'like', '%'. $buscar . '%')->orderBy('idfactura', 'desc')->paginate(4);
  28.         }
  29.  
  30.  
  31.         return [
  32.             'pagination' => [
  33.                 'total'        => $facturas->total(),
  34.                 'current_page' => $facturas->currentPage(),
  35.                 'per_page'     => $facturas->perPage(),
  36.                 'last_page'    => $facturas->lastPage(),
  37.                 'from'         => $facturas->firstItem(),
  38.                 'to'           => $facturas->lastItem(),
  39.             ],
  40.             'facturas' => $facturas /*it was 'factura' => $facturas and the object is plural this is in FacturaController*/
  41.         ];
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement