/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { $perPage = 20; $search = ['s' => $request->has('s') ? $request->input('s') : null, 'field' => $request->has('field') ? $request->input('field') : null]; $data = ['title' => 'Data List Material', 'asset' => new Assets(), 'position' => ['material' => 'Material'], 'fetch' => MatModel::fetchData(['search' => $search, 'perPage' => $perPage]), 'search' => $search, 'opened' => 'material', 'hak_akses' => $this->role, 'getNumb' => function () use($perPage, $request) { if ($request->has('page') && $request->input('page') != 1) { return $request->input('page') * $perPage - $perPage; } else { return 0; } }, 'isSelected' => function ($field) use($search) { if (!is_null($search['field'])) { if ($search['field'] == $field) { return 'selected="selected"'; } } }]; # Pagination config $data['fetch']->setPath(url('material')); if ($request->has('s')) { $data['fetch']->appends(['field' => $search['field'], 's' => $search['s']]); } # End of pagination config return view('material.index', $data); }