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
BlackShadow12mo ago
I think i have seen this before, do you have anything with global search columns in your UserResource ?
justaspark
justaspark12mo ago
Hey! Let me check Hmm, haven't done anything for search columns
BlackShadow
BlackShadow12mo ago
Can you share your UserResource
justaspark
justaspark12mo 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
BlackShadow12mo 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
justaspark12mo ago
Nada 😦 still "user" instead of the name of the user
BlackShadow
BlackShadow12mo 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
justaspark12mo 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
BlackShadow12mo ago
Mmmm Im not sure since i have not used it myself yet.
justaspark
justaspark12mo ago
Aww I see, thanks for the suggestion though! Super appreciate it :)))
BlackShadow
BlackShadow12mo ago
I will let you know if i figured it out, but i think its something with this:
justaspark
justaspark12mo ago
I tried using Global Search It crashes
justaspark
justaspark12mo ago
justaspark
justaspark12mo ago
I get this error I scanned all of my project files, and I have never used User::user()
toeknee
toeknee12mo ago
You need a user model... it might be at: App\User depending on how old your application is.
justaspark
justaspark12mo ago
I already have a model
justaspark
justaspark12mo ago
toeknee
toeknee12mo ago
Sorry, poorly read the message. It looks like you are doing it backwards, Where is your attach user field?
justaspark
justaspark12mo ago
Right here
justaspark
justaspark12mo ago
Within the UserRelationManager