continue;
}
$this->addField($field);
- }catch (\Error $e){
- dd($field,$e);
+ } catch (\Error $e) {
+ dd($field, $e);
}
}
+
+
+ foreach ($model->getFilters() as $filter) {
+ $this->crud->addFilter(['name' => $filter['name'], 'type' => $filter['type'], 'label' => $filter['label']], $filter['options'], function ($value) use ($filter) {
+ $f = $filter['logic'];
+ return $f($value, $this->crud);
+ });
+ }
}
*/
protected $editActions = [];
+ protected $filters = [];
+
/**
* @var array
$res = $this->getMedia($c);
if ($res->count() === 0 && $this->hasField($c)) {
$c = $this->getAttribute($c);
- if(null===$c){
+ if (null === $c) {
return [];
}
$res = $this->getMedia($c);
public function getFirstMediaInField(string $fieldName): ?Media
{
$collection = $this->getMediaInField($fieldName);
- if(!$collection){
+ if (!$collection) {
return null;
}
if ($collection->count() > 0) {
{
return true;
}
+
+ public function addFilter($name, $type, $label, $logic = null, $options = null)
+ {
+ $this->filters[$name] = ['name' => $name, 'type' => $type, 'label' => $label, 'logic' => $logic, 'options' => $options];
+ }
+
+ /**
+ * @return array[]
+ */
+ public function getFilters()
+ {
+ return $this->filters;
+ }
}