Reputation: 11
use Filament\Forms\Components\TextInput;
CreateAction::make()
->model(Post::class)
->form([
TextInput::make('title')
->required()
->maxLength(255),
// ...
])```
composer require filament/actions:"^3.0-stable" -W
But it resulted in an error:
Method Filament\Actions\CreateAction::table does not exist. Bad Method Call Did you mean Filament\Actions\CreateAction::disabled() ?
I tried this operation and also tried replacing the code examples with official examples, but both resulted in errors.
My code structure is as follows, and I've used // to omit some specific content:
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\BrowserResource\Pages;
use Filament\Actions\CreateAction;
use App\Models\Browser;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables\Table;
class BrowserResource extends Resource
{
protected static ?string $model = Browser::class;
protected static ?string $navigationGroup = '流量源-Facebook';
protected static ?string $navigationIcon = 'heroicon-o-window';
public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
//
])
->filters([
//
])
->actions([])
->bulkActions([
//
])
->headerActions([
CreateAction::make()
->icon("heroicon-o-arrow-down-circle")
->model(Post::class)
->form([
//
])
->action(function (array $data): void {
}),
])
->emptyStateActions([]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListBrowsers::route('/'),
'create' => Pages\CreateBrowser::route('/create'),
'edit' => Pages\EditBrowser::route('/{record}/edit'),
];
}
}
I really don't understand where the error is coming from. I've already imported use Filament\Actions\CreateAction;, but it keeps saying it doesn't exist. I've even re-downloaded it.
This is my composer.json file:
"filament/actions": "^3.0-stable",
"filament/filament": "^3.0-stable",
"filament/tables": "^3.0-stable",
I think the error should be like this.
Upvotes: 1
Views: 7115
Reputation: 1140
As mentioned here, you need to use Filament\Tables\Actions\CreateAction
instead of Filament\Actions\CreateAction
for table header actions.
Also, there's no need to require each filament package separately. Just require filament/filament
, filament actions, tables, ... will be installed automatically.
Here's a full code of my test:
use Filament\Tables;
use Filament\Forms;
...
public static function table(Table $table): Table
{
return $table
->columns([
//
])
->filters([
//
])
->actions([])
->bulkActions([
//
])
->headerActions([
Tables\Actions\CreateAction::make()
->form([
Forms\Components\TextInput::make('title')
->required()
->maxLength(255),
]),
])
->emptyStateActions([]);
}
Upvotes: 4