Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- //use Illuminate\Support\Facades\DB;
- use App\Factura;
- class FacturaController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index(Request $request)
- {
- if (!$request->ajax()) return redirect('/');
- $buscar = $request->buscar;
- $criterio = $request->criterio;
- if ($buscar==''){
- $facturas = Factura::orderBy('idfactura', 'desc')->paginate(4);
- }
- else{
- $facturas = Factura::where($criterio, 'like', '%'. $buscar . '%')->orderBy('idfactura', 'desc')->paginate(4);
- }
- return [
- 'pagination' => [
- 'total' => $facturas->total(),
- 'current_page' => $facturas->currentPage(),
- 'per_page' => $facturas->perPage(),
- 'last_page' => $facturas->lastPage(),
- 'from' => $facturas->firstItem(),
- 'to' => $facturas->lastItem(),
- ],
- 'facturas' => $facturas /*it was 'factura' => $facturas and the object is plural this is in FacturaController*/
- ];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement