Skip to content

Commit

Permalink
Add JSON fields support (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
milewski committed Sep 18, 2021
1 parent daeb354 commit fc7ec22
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/ConditionalContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace DigitalCreative\ConditionalContainer;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Laravel\Nova\Contracts\RelatableField;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Http\Controllers\ResourceUpdateController;
use Laravel\Nova\Http\Controllers\UpdateFieldController;
Expand Down Expand Up @@ -42,7 +42,7 @@ class ConditionalContainer extends Field
'===', '==', '=',
'includes', 'contains',
'ends with', 'starts with', 'startsWith', 'endsWith',
'boolean', 'truthy'
'boolean', 'truthy',
];

/**
Expand Down Expand Up @@ -108,14 +108,14 @@ public function resolve($resource, $attribute = null)
}

}
public function resolveForAction ($request)

public function resolveForAction($request)
{
$expressionsMap = $this->expressions->map(function ($expression) {
return is_callable($expression) ? $expression() : $expression;
});

$this->withMeta(['expressionsMap' => $expressionsMap]);
$this->withMeta([ 'expressionsMap' => $expressionsMap ]);

return $this->resolveUsing(function () { });
}
Expand Down Expand Up @@ -243,7 +243,7 @@ public static function splitLiteral(string $literal): array

$operator = collect(self::OPERATORS)
->filter(function ($operator) use ($literal) {
return strpos($literal, $operator) !== false;
return Str::of($literal)->replace('->', '.')->contains($operator);
})
->first();

Expand All @@ -254,7 +254,7 @@ public static function splitLiteral(string $literal): array
return [
$attribute,
$operator,
$value
$value,
];

}
Expand All @@ -270,7 +270,13 @@ public function runConditions(Collection $values): bool
return $this->relationalOperatorLeafResolver(...$arguments);
});

return $resolver($values);
return $resolver(
collect(Arr::dot($values))->mapWithKeys(function ($value, string $key) {
return [
Str::of($key)->replace('.', '->')->__toString() => $value,
];
})
);

});
}
Expand Down

0 comments on commit fc7ec22

Please sign in to comment.