标签:初始 get count arch 实例化 col collect tor adt
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
class AdnamesController extends Controller
{
public function index()
{
$info = DB::table(‘表名‘)->get([‘字段‘])->map(function ($value){
return (array)$value;
})->toArray();
$vs = [];
foreach($info as $v){
$vs[] = $v[‘mac‘];
}
$arr_info = array_count_values(array_filter($vs));
arsort($arr_info);
//获取当前的分页数 初始是1;
$currentPage = LengthAwarePaginator::resolveCurrentPage();
//实例化collect方法
$collection = new Collection($arr_info);
//定义一下每页显示多少个数据
$perPage =10;
//获取当前需要显示的数据列表
$currentPageSearchResults = $collection->slice(($currentPage-1) * $perPage, $perPage)->all();
//创建一个新的分页方法
$paginatedSearchResults_a= new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);
//储存路径防止下一页路径丢失
$arr_info = $paginatedSearchResults_a->setPath(‘/tool_ad‘);
return view(‘Admin.AdTool.index‘,[‘arr_info‘=>$arr_info]);
}
}
标签:初始 get count arch 实例化 col collect tor adt
原文地址:https://www.cnblogs.com/vinzen/p/10143991.html