Records in Attachment Dialog only show table name, not record name

Hey guys! New to Filament, and read the docs regarding this issue. For some odd reason, when searching for records to attach, it only shows the name of the table, and not the record itself. For example, I search for Sample User, in the list, it only shows "user" But when I select the user and attach, it shows the name of the user in the table in the Edit page. What do? 😦
21 Replies
BlackShadow
BlackShadow17mo ago
I think i have seen this before, do you have anything with global search columns in your UserResource ?
justaspark
justasparkOP17mo ago
Hey! Let me check Hmm, haven't done anything for search columns
BlackShadow
BlackShadow17mo ago
Can you share your UserResource
justaspark
justasparkOP17mo ago
Et voila. (thanks for helping out btw!)
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource\RelationManagers;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class UserResource extends Resource
{

protected static ?string $model = User::class;

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

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
Forms\Components\DateTimePicker::make('email_verified_at'),
Forms\Components\TextInput::make('password')
->password()
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone')
->tel()
->maxLength(255),
Forms\Components\DatePicker::make('date_of_birth'),
Forms\Components\TextInput::make('type')
->required()
->maxLength(255)
->default('staff'),
]);
}
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource\RelationManagers;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class UserResource extends Resource
{

protected static ?string $model = User::class;

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

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
Forms\Components\DateTimePicker::make('email_verified_at'),
Forms\Components\TextInput::make('password')
->password()
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone')
->tel()
->maxLength(255),
Forms\Components\DatePicker::make('date_of_birth'),
Forms\Components\TextInput::make('type')
->required()
->maxLength(255)
->default('staff'),
]);
}
2nd half:
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('email')
->searchable(),
Tables\Columns\TextColumn::make('email_verified_at')
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('phone')
->searchable(),
Tables\Columns\TextColumn::make('date_of_birth')
->date()
->sortable(),
Tables\Columns\TextColumn::make('type')
->searchable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('email')
->searchable(),
Tables\Columns\TextColumn::make('email_verified_at')
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('phone')
->searchable(),
Tables\Columns\TextColumn::make('date_of_birth')
->date()
->sortable(),
Tables\Columns\TextColumn::make('type')
->searchable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
3rd half:
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}

public static function getRelations(): array
{
return [
RelationManagers\ProjectsRelationManager::class,
];
}


public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}

public static function getRecordLabel($record): string
{
return $record->name; // Replace 'name' with the actual attribute you want to use for the label.
}

}
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}

public static function getRelations(): array
{
return [
RelationManagers\ProjectsRelationManager::class,
];
}


public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}

public static function getRecordLabel($record): string
{
return $record->name; // Replace 'name' with the actual attribute you want to use for the label.
}

}
BlackShadow
BlackShadow17mo ago
Can you try to add this:
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $recordTitleAttribute = 'name';
im not sure if its gonna work tho
justaspark
justasparkOP17mo ago
Nada 😦 still "user" instead of the name of the user
BlackShadow
BlackShadow17mo ago
Maybe you haven't specified the attach column name or something I have not used attached yet. You got the example of where you use it?
justaspark
justasparkOP17mo ago
I use it an a page called Projects, where you can attach Users to it. Hmm, I don't think I specified a column name for the attach system I only followed the Relationship Manager docs on Filament
BlackShadow
BlackShadow17mo ago
Mmmm Im not sure since i have not used it myself yet.
justaspark
justasparkOP17mo ago
Aww I see, thanks for the suggestion though! Super appreciate it :)))
BlackShadow
BlackShadow17mo ago
I will let you know if i figured it out, but i think its something with this:
justaspark
justasparkOP17mo ago
I tried using Global Search It crashes
justaspark
justasparkOP17mo ago
justaspark
justasparkOP17mo ago
I get this error I scanned all of my project files, and I have never used User::user()
toeknee
toeknee17mo ago
You need a user model... it might be at: App\User depending on how old your application is.
justaspark
justasparkOP17mo ago
I already have a model
justaspark
justasparkOP17mo ago
toeknee
toeknee17mo ago
Sorry, poorly read the message. It looks like you are doing it backwards, Where is your attach user field?
justaspark
justasparkOP17mo ago
Right here
justaspark
justasparkOP17mo ago
Within the UserRelationManager
Want results from more Discord servers?
Add your server