Steve_OH
Steve_OH
FFilament
Created by Steve_OH on 6/29/2024 in #❓┊help
Unique record within tenancy rather than across the board?
As the title suggests, I'm attempting to tighten up one of my tables with the 'unique' property and would like to scope the limitations entirely to the tenant rather than across the board. For example:
TextInput::make('slug')
->unique(Blogs::class, 'slug', ignoreRecord: true, modifyRuleUsing:
fn (Unique $rule, string $context, ?Model $record) =>
$rule->where('organizations_id', $record->organizations_id)
),
TextInput::make('slug')
->unique(Blogs::class, 'slug', ignoreRecord: true, modifyRuleUsing:
fn (Unique $rule, string $context, ?Model $record) =>
$rule->where('organizations_id', $record->organizations_id)
),
This should work for editing, but I can see a flaw for creation, when the record doesn't yet exist. What is the most efficient way to get this id other than by extracting it from the user? I ask as I have created the ability to create content for my clients and would prefer to have checks account for this as there may be issues in this case.
6 replies
FFilament
Created by Steve_OH on 5/1/2024 in #❓┊help
Any way to modify charts to only return a subset of data?
I'm attempting to create a user activity chart and presently have users organized into smaller sub-sets. I wondered if there was a way to only show chart results for users within the same user's sub-set list? For example
... // the widget
[$users, $months] = $this->getPerMonth();
... // rest of widget


private function getPerMonth(): array
{
$activity = UserActivity::get()->where('organizations_id', auth()->user()->organizations_id); // not in use currently
$data = Trend::model(UserActivity::class)
->between(
start: now()->startOfYear(),
end: now()->endOfYear(),
)
->perMonth()
->count();

return [
$data->map(fn (TrendValue $value) => $value->aggregate),
$data->map(fn (TrendValue $value) => now()->rawParse($value->date)->format('M')),
];
}
... // the widget
[$users, $months] = $this->getPerMonth();
... // rest of widget


private function getPerMonth(): array
{
$activity = UserActivity::get()->where('organizations_id', auth()->user()->organizations_id); // not in use currently
$data = Trend::model(UserActivity::class)
->between(
start: now()->startOfYear(),
end: now()->endOfYear(),
)
->perMonth()
->count();

return [
$data->map(fn (TrendValue $value) => $value->aggregate),
$data->map(fn (TrendValue $value) => now()->rawParse($value->date)->format('M')),
];
}
I'm wondering if there is a way to use the $activity variable somehow instead of the class? Or can I filter it after the values are returned from getPerMonth? Thanks in advance!
18 replies
FFilament
Created by Steve_OH on 4/20/2024 in #❓┊help
Local Storage and Production storages differ
Hey, so I'm having an issue setting storage. On my local installation, storage is located at directory/storage/files, whereas on the server they understandably go to directory/public/storage/files. How do I fix this? I attempted to do the storage link, but it said it was already set. I'm sure it is some simple config somewhere, but I appreciate any help that can be provided!
19 replies
FFilament
Created by Steve_OH on 4/13/2024 in #❓┊help
Is there a way to show html images inside an infolist?
In the Rich Text Editor you can add images, is there a way to display those images when viewing the record with an infolist? I tried the ->html() method, but the image does not show up, or maybe I've done something wrong? The infolist item is as follows:
TextEntry::make('description')
->label(__('Description'))
->color('primary')
->html()
->columnSpan([
'sm' => 2,
]),
TextEntry::make('description')
->label(__('Description'))
->color('primary')
->html()
->columnSpan([
'sm' => 2,
]),
Suggestions and help would be greatly appreciated!
6 replies
FFilament
Created by Steve_OH on 4/2/2024 in #❓┊help
Method for allowing full HTML/Markup in Table View
I'm attempting to create a ticketing program for my panel and thought it would make sense to use a table for any comments on the ticket. However, an issue arises whenever any real formatting comes into play for the comments. Take for example the following code used in my relation manager for the ticket comments (ignoring that card and enableDownload are depreciated):
public function form(Form $form): Form
{
return $form
->schema([
Card::make()->schema([
Forms\Components\RichEditor::make('comment')
->required()
->maxLength(255),
Forms\Components\FileUpload::make('attachments')
->directory('comment-attachments/' . date('m-y'))
->maxSize(2000)
->enableDownload(),
])
]);
}

public function table(Table $table): Table
{
return $table
->columns([
Stack::make([
Split::make([
TextColumn::make('user.name')
->translateLabel()
->color('primary')
->weight('bold')
->description(fn (Comments $record): string => $record->created_at, position: 'below')
->grow(false),
]),
TextColumn::make('comment')
->wrap()
->html(),
]),
])
->filters([])

// -- more stuff
}
public function form(Form $form): Form
{
return $form
->schema([
Card::make()->schema([
Forms\Components\RichEditor::make('comment')
->required()
->maxLength(255),
Forms\Components\FileUpload::make('attachments')
->directory('comment-attachments/' . date('m-y'))
->maxSize(2000)
->enableDownload(),
])
]);
}

public function table(Table $table): Table
{
return $table
->columns([
Stack::make([
Split::make([
TextColumn::make('user.name')
->translateLabel()
->color('primary')
->weight('bold')
->description(fn (Comments $record): string => $record->created_at, position: 'below')
->grow(false),
]),
TextColumn::make('comment')
->wrap()
->html(),
]),
])
->filters([])

// -- more stuff
}
The output displays the comments, but the comments are devoid of any real formatting. Is there a way to override the default table formatting behavior? Alternatively, would a repeater be best for this? If so, any good examples I can follow?
2 replies
FFilament
Created by Steve_OH on 3/22/2024 in #❓┊help
public access forms
Hello! First off, Filament is a fantastic framework that I am thoroughly enjoying. I’m wondering if it’s possible to set up a panel entirely for a form for guests? For example, a contact form, a survey, or a ticket? The table would exist for logged in users, but the creation would only exist on the guest panel. The form would act as a registration of sorts and would redirect or show a success page when done.
4 replies
FFilament
Created by Steve_OH on 3/8/2024 in #❓┊help
Any way to add filter to global search?
Not sure if I selected the right tag, but is there any way to add a search filter to global search? I have organizations set and would like to filter results of global search to remain within that organization. I've attempted the following function, which produces an empty result, but clicking it still links to the hidden result.
public static function getGlobalSearchResultTitle(Model $record): string|Htmlable
{

if($record['organizations_id'] == auth()->user()->organizations_id)
{
return $record['name'];
}
return '';
}
public static function getGlobalSearchResultTitle(Model $record): string|Htmlable
{

if($record['organizations_id'] == auth()->user()->organizations_id)
{
return $record['name'];
}
return '';
}
3 replies