Jamie Cee
Jamie Cee
FFilament
Created by Jamie Cee on 10/16/2024 in #❓┊help
Policies for ManageRelatedRecords only
So in my Model, I have a class that extends ManageRelatedRecords, and is for managing users under that model. I only want to allow the attaching and detaching under that Model, but still hiding access to users as a whole navigation, which I cant do, even when in the Manager class, I define the canViewAny method
3 replies
FFilament
Created by Jamie Cee on 10/16/2024 in #❓┊help
soft delete modify query using
When a resource table is setup to use modifyQueryUsing(). how can I make it still filter with the trashed() functionality from the filter section?
2 replies
FFilament
Created by Jamie Cee on 10/16/2024 in #❓┊help
MorphToMany Select Relationship
Im getting completely frazzled with MorphToMany setup in a select instance. I have a User that Morphs to Many Organisation and Product. Im trying to merge the items into a single Select, and I have it working, except when trying to edit a user, I cant get it to show the already existing records as already selected values. I found this function
->loadStateFromRelationshipsUsing(function (User $record) {
// Retrieve the organisation IDs managed by the user
$organisationIds = $record->morphedOrganisations()->pluck(
(new Organisation())->getQualifiedKeyName()
)->toArray();

// Retrieve the product IDs managed by the user
$productIds = $record->morphedProducts()->pluck(
(new Product())->getQualifiedKeyName()
)->toArray();

dd(array_merge($organisationIds, $productIds));

// Combine both arrays of IDs
return array_merge($organisationIds, $productIds);
})
->loadStateFromRelationshipsUsing(function (User $record) {
// Retrieve the organisation IDs managed by the user
$organisationIds = $record->morphedOrganisations()->pluck(
(new Organisation())->getQualifiedKeyName()
)->toArray();

// Retrieve the product IDs managed by the user
$productIds = $record->morphedProducts()->pluck(
(new Product())->getQualifiedKeyName()
)->toArray();

dd(array_merge($organisationIds, $productIds));

// Combine both arrays of IDs
return array_merge($organisationIds, $productIds);
})
I can get the array of ids, but im not sure what im missing at displaying them as the selected values
5 replies
FFilament
Created by Jamie Cee on 10/9/2024 in #❓┊help
deleteAny policy - prevent self deletion
When using the deleteAny policy to allow bulk deletion, how can I modify to prevent allowing the ability to bulk delete myself from the list
3 replies
FFilament
Created by Jamie Cee on 10/1/2024 in #❓┊help
Loading indicator on a custom action with alpineClickHandler
My action process is ran with alpinejs component rather than a submit action
public function securityKeyAction(): Action
{
$name = \App\Services\TwoFactorService::SECURITY_KEY_METHOD;
return Action::make("securitykey")
->label("Register new key")
->icon('heroicon-c-plus-circle')
->color('success')
->hidden(function () use ($name) {
return $this->config['methods'][$name]['enabled'] ? false : true;
})
->extraAttributes(['x-data' => 'registerPasskey', 'x-show' => 'browserSupportsWebAuthn()'])
->alpineClickHandler('register("' . Str::random(10) . '")');
}
public function securityKeyAction(): Action
{
$name = \App\Services\TwoFactorService::SECURITY_KEY_METHOD;
return Action::make("securitykey")
->label("Register new key")
->icon('heroicon-c-plus-circle')
->color('success')
->hidden(function () use ($name) {
return $this->config['methods'][$name]['enabled'] ? false : true;
})
->extraAttributes(['x-data' => 'registerPasskey', 'x-show' => 'browserSupportsWebAuthn()'])
->alpineClickHandler('register("' . Str::random(10) . '")');
}
But I want to display a loading indicator while it goes through the flow, but cant seem to find a way to show the indicator. The blade is rendering just with ```php {{$this->securityKeyAction}} rather than blade components for the button etc
6 replies
FFilament
Created by Jamie Cee on 9/24/2024 in #❓┊help
Edit Action unexpected character
I have a table with an edit action.
EditAction::make('edit')
->label('Rename')
->modalHeading('Rename Key')
->modalWidth('sm')
// ->form([
// Forms\Components\TextInput::make('name')
// ->label('Name')
// ->required()
// ->default(function ($record) {
// return $record->name;
// })
// ])
->action(function (array $data, $record) {
$record->update($data);
$this->service->sendNotification(
title: 'Successfully renamed key.',
success: true
);
}),
EditAction::make('edit')
->label('Rename')
->modalHeading('Rename Key')
->modalWidth('sm')
// ->form([
// Forms\Components\TextInput::make('name')
// ->label('Name')
// ->required()
// ->default(function ($record) {
// return $record->name;
// })
// ])
->action(function (array $data, $record) {
$record->update($data);
$this->service->sendNotification(
title: 'Successfully renamed key.',
success: true
);
}),
This opens the modal, but as soon as I uncomment the form, I get an error saying:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
And my table:
return $table
->query(Passkey::where('user_id', $this->user->getKey()))
return $table
->query(Passkey::where('user_id', $this->user->getKey()))
7 replies
FFilament
Created by Jamie Cee on 9/23/2024 in #❓┊help
underscore action name
Is it possible to have underscores in an action name, as that seems to prevent my action from working and just refreshes the page? key_name for example
3 replies
FFilament
Created by Jamie Cee on 9/12/2024 in #❓┊help
Struggling to find how to trigger a loader
So I want to trigger a loader when I press a toggle button and the state is true. But I cant seem to find anywhere on what the target must be set. Calling a function name doesn't seem to be working, nor a variable name?
7 replies
FFilament
Created by Jamie Cee on 9/4/2024 in #❓┊help
Toggle Input afterStateUpdated not doing anything
I have my Toggle component and have ->afterStateUpdated just to dd currently, but when I press the toggle button, nothing is happening
7 replies
FFilament
Created by Jamie Cee on 9/3/2024 in #❓┊help
Preload options limit from relation page
I have a relation page, and when I go to attach my relation, its all searcahable, but how can I add a preload with 5 records?
class ManageOrganisationProducts extends ManageRelatedRecords
{
protected static string $resource = OrganisationResource::class;

protected static string $relationship = 'products';

protected static ?string $navigationIcon = 'heroicon-o-square-3-stack-3d';

public static function getNavigationLabel(): string
{
return 'Products';
}

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Grid::make(1)
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\Toggle::make('enabled')
->required(),
]),
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
])
->filters([])
->headerActions([
Tables\Actions\AttachAction::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\DetachAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DetachBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
])
->modifyQueryUsing(fn(Builder $query) => $query->withoutGlobalScopes([
SoftDeletingScope::class,
]));
}
}
class ManageOrganisationProducts extends ManageRelatedRecords
{
protected static string $resource = OrganisationResource::class;

protected static string $relationship = 'products';

protected static ?string $navigationIcon = 'heroicon-o-square-3-stack-3d';

public static function getNavigationLabel(): string
{
return 'Products';
}

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Grid::make(1)
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\Toggle::make('enabled')
->required(),
]),
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
])
->filters([])
->headerActions([
Tables\Actions\AttachAction::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\DetachAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DetachBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
])
->modifyQueryUsing(fn(Builder $query) => $query->withoutGlobalScopes([
SoftDeletingScope::class,
]));
}
}
5 replies
FFilament
Created by Jamie Cee on 9/3/2024 in #❓┊help
Opening modal from a custom page
Is it possible to open a modal from a class that extends Page? $this->dispatch doesn't seem to be working, I want the modal to automatically open at the end of my submit function
34 replies
FFilament
Created by Jamie Cee on 8/20/2024 in #❓┊help
Feedback on FullCalendar Plugin
Just initially looking into available plugins for a use case that would be a booking system with calendar integration to select available slots with particular instructors. Has anyone had similar exposure to the FullCalendar with a similar use case? And able to share your experience with it, was there any complications etc
8 replies
FFilament
Created by Jamie Cee on 8/12/2024 in #❓┊help
Laracasts Alpine code in an action
Im following a guide on laracasts and im at a point for it has a form component, and has attributes for: x-data, x-on:submit.prevent. I am wondering if I can use a custom action to call the alpinejs function from my app.js file, rather than creating a new blade file etc Bit lost trying to find this in the docs?
41 replies
FFilament
Created by Jamie Cee on 8/6/2024 in #❓┊help
Read/Write Databases
Is there any configuration available for separate read/write database instances? Currently my list in my resource is empty since I added the configuration for separate read/write database hosts
2 replies
FFilament
Created by Jamie Cee on 8/5/2024 in #❓┊help
Not authenticating on login
Not sure what step im missing... When I go to my login page, and login. It just redirects straight back to the login page. If I go to the Authenticate middleware, and dump out $guard = Filament::auth(); it returns false... Not sure why?
4 replies
FFilament
Created by Jamie Cee on 7/10/2024 in #❓┊help
Pagination with options
I have a view
<div>
{{ $this->productInfolist }}

<x-filament::pagination :paginator="$this->data['budgetPagination']" style="margin-top: 15px;"
:page-options="[1, 5, 10, 20, 50, 'all']" :current-page-option-property="$this->perPage" />
{{-- /> --}}
</div>
<div>
{{ $this->productInfolist }}

<x-filament::pagination :paginator="$this->data['budgetPagination']" style="margin-top: 15px;"
:page-options="[1, 5, 10, 20, 50, 'all']" :current-page-option-property="$this->perPage" />
{{-- /> --}}
</div>
And in my Page class, I define
public int | string $perPage = 5;
protected static string $view = 'filament.pages.report';
public int | string $perPage = 5;
protected static string $view = 'filament.pages.report';
Then I have my productInfolist function return an InfoList. So now pagination works to perPage, but when I change the options, nothing happens. Any ideas?
2 replies
FFilament
Created by Jamie Cee on 7/10/2024 in #❓┊help
Reactive filter updating
So on my custom page, where I have a filtersForm. Its generated with:
public function filtersForm(Form $form): Form
{
return $form->schema([
Forms\Components\Section::make('Filters')
->schema([
Forms\Components\Grid::make(4)
->schema([
Forms\Components\Select::make('client')
->label('Client')
->placeholder('Select a client')
->options($this->getClientOptions())
->default(''),

Forms\Components\Select::make('project')
->label('Project')
->placeholder('Search for a project')
->options($this->getProjectOptions())
->default(''),
])
])
->collapsed()
->persistCollapsed(),
]);
}

/**
* Client filter dropdown
*
* @return array
*/
protected function getClientOptions(): array
{
$client = \App\Models\Client::query();

if (empty($this->filters['client'])) {
$this->filters['project'] = null;
}

return $client->pluck('name', 'id')->toArray();
}

protected function getProjectOptions()
{
$project = \App\Models\Project::query();

if (!empty($this->filters['client'])) {
$project->where('client_id', $this->filters['client']);
}

return $project->pluck('name', 'id')->toArray();
}
public function filtersForm(Form $form): Form
{
return $form->schema([
Forms\Components\Section::make('Filters')
->schema([
Forms\Components\Grid::make(4)
->schema([
Forms\Components\Select::make('client')
->label('Client')
->placeholder('Select a client')
->options($this->getClientOptions())
->default(''),

Forms\Components\Select::make('project')
->label('Project')
->placeholder('Search for a project')
->options($this->getProjectOptions())
->default(''),
])
])
->collapsed()
->persistCollapsed(),
]);
}

/**
* Client filter dropdown
*
* @return array
*/
protected function getClientOptions(): array
{
$client = \App\Models\Client::query();

if (empty($this->filters['client'])) {
$this->filters['project'] = null;
}

return $client->pluck('name', 'id')->toArray();
}

protected function getProjectOptions()
{
$project = \App\Models\Project::query();

if (!empty($this->filters['client'])) {
$project->where('client_id', $this->filters['client']);
}

return $project->pluck('name', 'id')->toArray();
}
I want project to update live with my data when client changes. So for example, I select client 1, and select project 1 (as that belongs to client 1). If I then change to Client 2, I need Project 1 to reset when it changes, so I can also populate the infolist live, being returned.
5 replies
FFilament
Created by Jamie Cee on 7/9/2024 in #❓┊help
Page Filters with InfoLists not working
I have a lot going on here and not too sure whats causing what. So currently happening: I can change a filter and the response will update, but if I remove the filter back to "select a x". The data goes blank, I want this to reset that filter and display all data as normal (well, minus that filter I just removed). Is it possible to get the table style filters instead, that may be easier?
9 replies
FFilament
Created by Jamie Cee on 7/8/2024 in #❓┊help
Paginated InfoLists
Is it possible to paginate info lists? I have a custom page with an infolist just to collect a collection of data from multiple relations into something readable, but there may be many records, so want to implement pagination into it.
4 replies
FFilament
Created by Jamie Cee on 6/17/2024 in #❓┊help
Live notifications
Im a little confused how notifications are working. So I've setup and installed pusher and echo etc. This is my notification
$message = $e->getMessage();
Notification::make()
->title('Translation failed')
->body($message)
->broadcast($this->initiator);
$message = $e->getMessage();
Notification::make()
->title('Translation failed')
->body($message)
->broadcast($this->initiator);
I have a queue:listen going, I can see the BroadcastNotificationCreated event, I can see in my pusher dashboard, the channel message come through and tells me the format is filament etc. But no notification comes through while im on my admin panel. What am I missing?
5 replies