Replies: 8 comments 4 replies
-
|
Why can you not include/exclude them from the panel provider? |
Beta Was this translation helpful? Give feedback.
-
|
Hello, The modules are developed independently, and each can have as many as 5 different resources - it's not possible to know all the resources beforehand. We had an issue with models and ended up using |
Beta Was this translation helpful? Give feedback.
-
|
Something like: public function getResources(): array
{
$resources = filled($this->getIncludes())
? $this->getIncludes()
: $this->evaluate($this->getResourcesUsing);
$list = collect($resources)
->filter(fn ($item): bool => ! in_array($item, $this->getExcludes()))
->map(function ($resourceName): ?array {
$resource = app($resourceName);
if (Filament::hasTenancy() && ! Filament::getTenant()) {
return null;
}
/// we add this simple check here
if(method_exists($resource, 'excludeFromQuickCreate') && true === $resource->excludeFromQuickCreate) {
return null;
}
if ($resource->canCreate()) {
... rest of code |
Beta Was this translation helpful? Give feedback.
-
|
Hello, thank you for your guidance. However, it did not work for me. A suggestion: perhaps pass the resolved resources to the callback function so that we dont't have to call So then the userland implementation could be as follows: ...
->getResourcesUsing(function ($resources) {
// here one can use array_map or array_filter to remove the resouces they don't need based on a flag
})This would be done in the |
Beta Was this translation helpful? Give feedback.
-
|
Are you using includes() and getResourcesUsing() at the same time? |
Beta Was this translation helpful? Give feedback.
-
|
Can you give me a reproduction repo? I'm struggling to see the issue since the method isn't called until after the filament lifecycle has completed. It doesn't make sense to me that you're getting an empty array for the resources off the filament facade. |
Beta Was this translation helpful? Give feedback.
-
|
Ie, it doesn't make sense to me to pass resources into method whose responsibility is to get the resources. |
Beta Was this translation helpful? Give feedback.
-
|
It's okay. I figured out a way. Created a custom Livewire component and use a renderHook, achieved what I needed with the following: <?php
namespace App\Livewire;
use Filament\Facades\Filament;
use Illuminate\Support\Str;
use Livewire\Component;
class QuickCreate extends Component
{
public array $resources = [];
public function mount(): void
{
$this->resources = collect(Filament::getCurrentOrDefaultPanel()->getResources())
->filter(fn ($resource) => !(app($resource)->disableQuickCreate ?? false))
->map(function ($resource) {
$instance = app($resource);
return [
'label' => Str::singular($instance->getNavigationLabel()),
'icon' => $instance->getNavigationIcon(),
'link' => $instance->getUrl('create'),
];
})
->values()
->toArray();
}
public function render()
{
return <<<'blade'
<x-filament::dropdown placement="bottom-start">
<x-slot name="trigger">
<x-filament::icon-button
icon="heroicon-m-plus"
color="gray"
size="lg"
tooltip="Create"
/>
</x-slot>
<x-filament::dropdown.list>
@foreach ($resources as $resource)
<x-filament::dropdown.list.item
:icon="$resource['icon']"
:href="$resource['link']"
tag="a"
>
{{ $resource['label'] }}
</x-filament::dropdown.list.item>
@endforeach
</x-filament::dropdown.list>
</x-filament::dropdown>
blade;
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
First of all, thank you so much for this plugin, it's the best!
I'm using it in conjunction with the filament modules plugin, and a lot of resources, and indeed models, are in the respective modules, and for separation of concerns, I cannot include/exclude them in the panel provider configuration.
My suggestion: we can have a
protected static $isExcludedFromQuickCreatevariable orfunction isExcudedFromQuickCreate(): bool {}method that will determine whether the resource should be shown or not.As you can see in the image above, pretty much all the menus on the left are clusters from separate modules, and some of the resources showing up on the Quick create need to be excluded
Beta Was this translation helpful? Give feedback.
All reactions