Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the deletion of a file #59

Merged
merged 15 commits into from
Nov 15, 2020
Merged
38 changes: 38 additions & 0 deletions src/FieldCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Eminiarts\Tabs;

use Illuminate\Support\Arr;
use Laravel\Nova\Fields\FieldCollection as NovaFieldCollection;

class FieldCollection extends NovaFieldCollection
{
/**
* Retrieve the field match matches the instance.
*
* @param string $type
* @return \Eminiarts\Tabs\FieldCollection
*/
public function whereInstanceOf($type)
{
return $this->flatMap(function ($tab) use ($type) {
return collect(Arr::get($tab, 'fields'))->whereInstanceOf($type);
});
}

public function findFieldByAttribute($attribute, $default = null)
{
foreach ($this->items as $field) {
if (isset($field->attribute) && $field->attribute === $attribute) {
return $field;
}

// Search the fields inside tabs.
if (is_array($field) && isset($field['component']) && $field['component'] === 'tabs') {
return static::make($field['fields'])->findFieldByAttribute($attribute, $default);
}
}

return null;
}
}
1 change: 1 addition & 0 deletions src/TabsOnEdit.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Eminiarts\Tabs;

use Laravel\Nova\Fields\FieldCollection;
Expand Down