F
Filament15mo ago
jey

how to save user_id on create and limit records per user

as the title says , i want to save current logged in user_id when i save a form that will associated with the user and how to limit user to create one only record , for example a user will create a business profile , i want him to be only able to create only one business profile not as many as he wants
9 Replies
krekas
krekas15mo ago
there is a method mudatedatabeforesave or something very similar to that. use it to add your logged in user
jey
jeyOP15mo ago
yes this helped a lot appreciated getting Method Filament\Actions\CreateAction::table does not exist. code :
public static function table(Table $table): Table
{
return $table
->headerActions([
CreateAction::make()
])
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('phone')
->searchable(),
Tables\Columns\TextColumn::make('email')
->searchable(),
Tables\Columns\TextColumn::make('website')
->searchable(),
Tables\Columns\TextColumn::make('address')
->searchable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}
public static function table(Table $table): Table
{
return $table
->headerActions([
CreateAction::make()
])
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('phone')
->searchable(),
Tables\Columns\TextColumn::make('email')
->searchable(),
Tables\Columns\TextColumn::make('website')
->searchable(),
Tables\Columns\TextColumn::make('address')
->searchable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}
krekas
krekas15mo ago
because it's a table from namescape
jey
jeyOP15mo ago
well i found the correct way i just had to use the pages actions under my resource ( im using v3 ) i'm just having problem limiting user creating more records than one
krekas
krekas15mo ago
make a check if user has record
jey
jeyOP15mo ago
is there any method i can use?
krekas
krekas15mo ago
exists on the model for example
jey
jeyOP15mo ago
well i found that i can just limit by disabling the create action button on any condition
Want results from more Discord servers?
Add your server