50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Support\Facades\Request;
|
|
use Nwidart\Modules\Facades\Module as ModuleManager;
|
|
|
|
class Module extends Model
|
|
{
|
|
/**
|
|
* Notes : 自定义返回数据
|
|
*
|
|
* @Date : 2021/3/11 9:59 上午
|
|
* @Author : <Jason.C>
|
|
* @return LengthAwarePaginator
|
|
*/
|
|
public function paginate(): LengthAwarePaginator
|
|
{
|
|
$perPage = Request::get('per_page', 20);
|
|
$page = Request::get('page', 1);
|
|
|
|
$data = ModuleManager::toCollection();
|
|
|
|
$chunk = $data->forPage($page, $perPage);
|
|
|
|
$modules = $chunk->map(function ($module) {
|
|
return [
|
|
'id' => $module->getName(),
|
|
'name' => $module->getName(),
|
|
'alias' => $module->getAlias(),
|
|
'description' => $module->getDescription(),
|
|
'priority' => $module->getPriority(),
|
|
'keywords' => $module->get('keywords'),
|
|
'requires' => $module->getRequires(),
|
|
'enabled' => $module->isEnabled(),
|
|
'version' => $module->get('version'),
|
|
'author' => $module->get('author'),
|
|
];
|
|
});
|
|
|
|
$modules = static::hydrate($modules->toArray());
|
|
$paginator = new LengthAwarePaginator($modules, ModuleManager::count(), $perPage);
|
|
$paginator->setPath(url()->current());
|
|
|
|
return $paginator;
|
|
}
|
|
}
|