Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Nov 23, 2023
1 parent 5aedd4b commit c3617a1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
26 changes: 25 additions & 1 deletion src/Fields/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function isNullable(): bool
}

/**
* Set the searachable attribute.
* {@inheritdoc}
*/
public function searchable(bool|Closure $value = true, array $columns = ['id']): static
{
Expand All @@ -218,6 +218,18 @@ public function getSearchableColumns(): array
return $this->searchableColumns;
}

/**
* {@inheritdoc}
*/
public function isSearchable(): bool
{
if ($this->isSubResource()) {
return false;
}

return parent::isSearchable();
}

/**
* Set the sortable attribute.
*/
Expand All @@ -236,6 +248,18 @@ public function getSortableColumn(): string
return $this->sortableColumn;
}

/**
* {@inheritdoc}
*/
public function isSortable(): bool
{
if ($this->isSubResource()) {
return false;
}

return parent::isSortable();
}

/**
* Set the display resolver.
*/
Expand Down
18 changes: 18 additions & 0 deletions src/Fields/URL.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Cone\Root\Fields;

use Closure;

class URL extends Text
{
/**
* Create a new field instance.
*/
public function __construct(string $label, Closure|string $modelAttribute = null)
{
parent::__construct($label, $modelAttribute);

$this->type('url');
}
}
10 changes: 6 additions & 4 deletions src/Filters/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Relation as EloquentRelation;
use Illuminate\Database\Query\Expression;
use Illuminate\Http\Request;

class Sort extends Filter
Expand Down Expand Up @@ -53,11 +54,12 @@ public function apply(Request $request, Builder $query, mixed $value): Builder
$relation = EloquentRelation::noConstraints(static function () use ($query, $value): EloquentRelation {
$relation = call_user_func([$query->getModel(), $value['by']]);

$key = $relation instanceof BelongsTo
? $relation->getQualifiedOwnerKeyName()
: $relation->getQualifiedParentKeyName();
$key = match (true) {
$relation instanceof BelongsTo => $relation->getQualifiedOwnerKeyName(),
default => $relation->getQualifiedParentKeyName(),
};

return $relation->whereField($relation->getQualifiedForeignKeyName(), '=', $key);
return $relation->whereColumn($relation->getQualifiedForeignKeyName(), $key);
});

return $query->orderBy(
Expand Down

0 comments on commit c3617a1

Please sign in to comment.