name and avatar in one using prefix
i am using this code for that functionallity
it s my code i am doing this but why i am not able to get image s3 said me access denied why or any other method to get the user image and name at one place
Tables\Columns\ImageColumn::make('profile_photo')
->circular()->label('')->extraImgAttributes(['loading' => 'lazy'])->height(30)
->defaultImageUrl(fn (Model $record) => 'https://ui-avatars.com/api/?name=' . $record->name . '&color=ffffff&background=5a51ec')
->disk('s3')
->visibility('private'),
Tables\Columns\TextColumn::make('name')
->numeric()
->sortable()
->searchable()
->prefix(function (Model $record): HtmlString {
// Check if the profile_photo exists in S3
if ($record->profile_photo !== null && Storage::disk('s3')->exists($record->profile_photo)) {
$profilePhotoUrl = Storage::disk('s3')->url($record->profile_photo);
} else {
// If the profile_photo doesn't exist or is null, use a default image
$profilePhotoUrl = 'https://ui-avatars.com/api/?name=' . $record->name . '&color=ffffff&background=5a51ec';
}
// Create the image HTML tag
$imageTag = '<img src="' . $profilePhotoUrl . '" style="display: inline-block; border-radius: 9999px; width: 32px; height: 32px; margin-right: 0.5rem;"/>';
return new HtmlString($imageTag);
})
->html(),
Tables\Columns\ImageColumn::make('profile_photo')
->circular()->label('')->extraImgAttributes(['loading' => 'lazy'])->height(30)
->defaultImageUrl(fn (Model $record) => 'https://ui-avatars.com/api/?name=' . $record->name . '&color=ffffff&background=5a51ec')
->disk('s3')
->visibility('private'),
Tables\Columns\TextColumn::make('name')
->numeric()
->sortable()
->searchable()
->prefix(function (Model $record): HtmlString {
// Check if the profile_photo exists in S3
if ($record->profile_photo !== null && Storage::disk('s3')->exists($record->profile_photo)) {
$profilePhotoUrl = Storage::disk('s3')->url($record->profile_photo);
} else {
// If the profile_photo doesn't exist or is null, use a default image
$profilePhotoUrl = 'https://ui-avatars.com/api/?name=' . $record->name . '&color=ffffff&background=5a51ec';
}
// Create the image HTML tag
$imageTag = '<img src="' . $profilePhotoUrl . '" style="display: inline-block; border-radius: 9999px; width: 32px; height: 32px; margin-right: 0.5rem;"/>';
return new HtmlString($imageTag);
})
->html(),
2 Replies