© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
16 replies
Crylar

Filling default value in forms via relationship

So lets say I have Categories that have a single Menu. Is there a way to create a dummy record with
menu_id
menu_id
pre-defined, so when I am creating it would just fetch based on a defined
menu_id
menu_id
and fill a
title
title
from the Menu

    public static function form(Form $form): Form
    {
        $defaultMenuId = Route::current()->parameter('menu');

        return $form->schema([
            Forms\Components\Card::make([
                Forms\Components\Grid::make()
                    ->relationship('menu')
                    ->columns(0)
                    ->schema([
                        Forms\Components\TextInput::make('title')
                            ->dehydrated(false)     // prevent saving to database
                            ->label('Menu')
                            ->disabled()
                            ->required()
                    ]),
            Forms\Components\Hidden::make('menu_id')
                    ->default($defaultMenuId),
    public static function form(Form $form): Form
    {
        $defaultMenuId = Route::current()->parameter('menu');

        return $form->schema([
            Forms\Components\Card::make([
                Forms\Components\Grid::make()
                    ->relationship('menu')
                    ->columns(0)
                    ->schema([
                        Forms\Components\TextInput::make('title')
                            ->dehydrated(false)     // prevent saving to database
                            ->label('Menu')
                            ->disabled()
                            ->required()
                    ]),
            Forms\Components\Hidden::make('menu_id')
                    ->default($defaultMenuId),


In a regular Laravel I could just:

    $category = Category::make(['menu_id' => $defaultMenuId]);
    $category->menu->title;    // and reach title without category created in the database
    $category = Category::make(['menu_id' => $defaultMenuId]);
    $category->menu->title;    // and reach title without category created in the database


How would it be possible to achieve a similar logic in a filament? Thanks.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Relationship in forms textinput?
FilamentFFilament / ❓┊help
3y ago
Select with relationship and default value
FilamentFFilament / ❓┊help
2y ago
Filling in hasMany relationship from Filament form
FilamentFFilament / ❓┊help
3y ago
Old value in relationship manager
FilamentFFilament / ❓┊help
3y ago