Filament: Asset Stock Management

Stock management application, with export/import the items and log the transactions on the change of the stock numbers.

Screenshot 2023-10-17 at 07.22.58

Get the Source Code:

How it works

We have a simple resource to manage categories where the create and edit form opens in a modal. For category, we only have one field, name. Here is the code for CategoryResource:

class CategoryResource extends Resource
{
protected static ?string $model = Category::class;
 
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
 
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name'),
]);
}
 
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
 
public static function getPages(): array
{
return [
'index' => Pages\ManageCategories::route('/'),
];
}
}

Transactions resource manages transactions for an item. We can only create a new transaction.

The form of transaction is reused in the relation manager for ItemResource. We don't need a select input in the relation manager, so the hiddenOn() method is used where the Relation Manager class is passed as a parameter.

The amount text input has a column span of full only in the Relation Manager. Here is the code for the form in the TransactionResource:

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('item_id')
->preload()
->required()
->searchable()
->label('Item')
->native(false)
->relationship('item', 'name')
->hiddenOn(TransactionsRelationManager::class),
Forms\Components\TextInput::make('amount')
->numeric()
->required()
->columnSpan(fn(HasForms $livewire) => $livewire instanceof TransactionsRelationManager ? 'full' : null),
Forms\Components\Textarea::make('comment')
->columnSpanFull(),
]);
}

The transactions create() method is overwritten to use DB transaction. After successfully creating the transaction and updating the item's stock, the user is redirected...

The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.
Get the Source Code: All 50 Premium Examples for $99 Only Project Examples for $59