F
Filament10mo ago
HiJoe

New instantly creates a new record

Hi, I tried to make a simple resource and I got this right now:
<?php

namespace Joebatta\Sooposted\Filament\Resources;

use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Joebatta\Sooposted\Filament\Resources\AccountResource\Pages\ManageAccounts;
use Joebatta\Sooposted\Models\Account;

class AccountResource extends Resource
{
protected static ?string $model = Account::class;

protected static ?string $navigationGroup = 'Test';

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}

public static function table(Table $table): Table
{
return $table
->contentGrid([
//
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}

public static function getPages(): array
{
return [
'index' => ManageAccounts::route('/'),
];
}
}
<?php

namespace Joebatta\Sooposted\Filament\Resources;

use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Joebatta\Sooposted\Filament\Resources\AccountResource\Pages\ManageAccounts;
use Joebatta\Sooposted\Models\Account;

class AccountResource extends Resource
{
protected static ?string $model = Account::class;

protected static ?string $navigationGroup = 'Test';

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}

public static function table(Table $table): Table
{
return $table
->contentGrid([
//
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}

public static function getPages(): array
{
return [
'index' => ManageAccounts::route('/'),
];
}
}
But when creating it instantly creates a empty record (yes fields are now nullable for testing)
No description
2 Replies
Panda
Panda10mo ago
This is because you have not defined anything in your form method. Either define fields in the form builder or disable the create button.
HiJoe
HiJoe10mo ago
You saved the day!