Skip to content

Commit

Permalink
wip: add makable to filter field
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasan Deeb committed Jul 4, 2024
1 parent 5809731 commit b78b457
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/DTO/FilterField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace Aldeebhasan\NaiveCrud\DTO;

use Aldeebhasan\NaiveCrud\Traits\Makable;

/**@method static FilterField make(string $field, ?string $column = null, ?string $operator = '=', callable $callback = null, mixed $value = null) */
final readonly class FilterField
{
use Makable;

public ?string $column;

public mixed $callback;
Expand Down
1 change: 0 additions & 1 deletion src/Http/Controllers/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Aldeebhasan\NaiveCrud\Logic\Managers\FileManager;
use Aldeebhasan\NaiveCrud\Traits\Crud\ResponseTrait;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Symfony\Component\HttpFoundation\Response;
Expand Down
13 changes: 7 additions & 6 deletions src/Logic/Managers/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class FileManager
protected array $thumbnailDim = [];

protected string $file;

protected array $meta = [
'mime' => 'image/jpeg',
'size' => "1024",
'size' => '1024',
'extension' => 'jpeg',
];

Expand All @@ -40,7 +41,7 @@ public function setFile(UploadedFile|string $file): self
];
$this->file = file_get_contents($file);
} else {
if (str($file)->startsWith("http")) {
if (str($file)->startsWith('http')) {
$this->file = file_get_contents($file);
} else {
$file = $this->getStoragePath($file);
Expand Down Expand Up @@ -88,7 +89,7 @@ public function uploadImage(string $name = ''): array
}
$encoded = $image->encodeByExtension($this->meta['extension'], quality: 75)->toString();

$name = $name ?: (time() . uniqid());
$name = $name ?: (time().uniqid());
$response = $this->upload($encoded, $name);

$this->generateThumbnail($name);
Expand All @@ -98,7 +99,7 @@ public function uploadImage(string $name = ''): array

protected function generateThumbnail(string $name): void
{
if (!$this->thumbnail) {
if (! $this->thumbnail) {
return;
}

Expand All @@ -118,8 +119,8 @@ public function uploadFile(string $name = ''): array

private function upload(string $file, string $name): array
{
$name = $name ?: (time() . uniqid());
$name = "$name." . $this->meta['extension'];
$name = $name ?: (time().uniqid());
$name = "$name.".$this->meta['extension'];
$path = "$this->path/$name";
Storage::put($this->getStoragePath($path), $file, 'public');
$path = $this->getAssetPath($path);
Expand Down
2 changes: 2 additions & 0 deletions src/Traits/Crud/IndexTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
trait IndexTrait
{
protected bool $paginated = true;

protected bool $preserveQueryParams = true;

protected array $paginationMeta = ['current_page', 'from', 'last_page', 'path', 'per_page', 'to', 'total'];

protected function indexQuery(Builder $query): Builder
Expand Down

0 comments on commit b78b457

Please sign in to comment.