Skip to content

Commit

Permalink
add isBadge() for table badge & pagainte() to base
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Sep 15, 2022
1 parent ca2f20a commit a23767d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Services/Concerns/IsBadge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Modules\Base\Services\Concerns;

trait IsBadge
{
/**
* @var ?bool
*/
public ?bool $badge = false;

/**
* @return $this
*/
public function badge(bool $badge = true): static
{
$this->badge = $badge;
return $this;
}
}
10 changes: 10 additions & 0 deletions Services/Resource/Concerns/Helpers/GenerateNameHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Modules\Base\Services\Resource\Concerns\Helpers;

use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

trait GenerateNameHelper
Expand Down Expand Up @@ -30,4 +33,11 @@ public function generateName(bool $single = false, bool $space = false): string

return Str::ucfirst($tableName);
}

public function paginate($items, $perPage = 10, $page = null, $options = []): LengthAwarePaginator
{
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options);
}
}
2 changes: 2 additions & 0 deletions Services/Rows/Abstracts/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Modules\Base\Services\Concerns\HasTrack;
use Modules\Base\Services\Concerns\HasType;
use Modules\Base\Services\Concerns\HasValidation;
use Modules\Base\Services\Concerns\IsBadge;
use Modules\Base\Services\Concerns\IsDisabled;
use Modules\Base\Services\Concerns\IsMoney;
use Modules\Base\Services\Concerns\IsMulti;
Expand Down Expand Up @@ -69,4 +70,5 @@ abstract class Base implements Component
use IsSearchable;
use IsMoney;
use IsSortable;
use IsBadge;
}

0 comments on commit a23767d

Please sign in to comment.