Pritbor
Pritbor
FFilament
Created by Pritbor on 11/18/2024 in #❓┊help
Don't want Create Form to show if No Subscription
I want to show No Subscription notification without showing Create Form when user clicks on Create button in List Page. I have this in create page. I also tried beforeFill but halt gives error.
protected function handleRecordCreation(array $data): Model
{
$data['reference'] = RandomStringGeneratorService::generateRandomString();
$data['member_id'] = Auth::user()->member->id;

if ($data['is_published'] === true){
$data['published_by'] = Auth::id();
$data['published_at'] = now();
}
else{
$data['published_by'] = null;
$data['published_at'] = null;
}
// Unset the 'is_published' field
unset($data['is_published']);

return static::getModel()::create($data);
}

protected function beforeCreate(): void
{
$subscriptionService= app(SubscriptionService::class);
if (! $subscriptionService->canPerformAction(auth()->user()->member, ModelType::JOB_SEEKING_POST, 'create')) {
Notification::make()
->warning()
->title('You don\'t have an active subscription!')
->body('Choose a plan to continue.')
->persistent()
->actions([
Action::make('subscribe')
->button()
->url(route('subscribe'), shouldOpenInNewTab: true),
])
->send();

$this->halt();
}
}
protected function handleRecordCreation(array $data): Model
{
$data['reference'] = RandomStringGeneratorService::generateRandomString();
$data['member_id'] = Auth::user()->member->id;

if ($data['is_published'] === true){
$data['published_by'] = Auth::id();
$data['published_at'] = now();
}
else{
$data['published_by'] = null;
$data['published_at'] = null;
}
// Unset the 'is_published' field
unset($data['is_published']);

return static::getModel()::create($data);
}

protected function beforeCreate(): void
{
$subscriptionService= app(SubscriptionService::class);
if (! $subscriptionService->canPerformAction(auth()->user()->member, ModelType::JOB_SEEKING_POST, 'create')) {
Notification::make()
->warning()
->title('You don\'t have an active subscription!')
->body('Choose a plan to continue.')
->persistent()
->actions([
Action::make('subscribe')
->button()
->url(route('subscribe'), shouldOpenInNewTab: true),
])
->send();

$this->halt();
}
}
4 replies
FFilament
Created by Pritbor on 11/17/2024 in #❓┊help
Reset option in toggleable() dropdown for table column to default
How to provide user with an option to reset to default toggleable() table columns. I wanted to include such reset in toggleable dropdown action.
2 replies
FFilament
Created by Pritbor on 11/14/2024 in #❓┊help
UserMenuItem with User Tenant Switch Option
I want to have tenant switch option in UserPanel and TenantPanel user menu item area in top right corner in menu drop down of panel. How to achieve this.
5 replies
FFilament
Created by Pritbor on 10/29/2024 in #❓┊help
Spatie Permission on filament Multi-tenancy
I am confused how to implment spatie permission for below multi-tenancy design. I have enabled team feature in spatie .I have below three filament panels:- 1. Admin Panel (only accessed by users who will be responsible for managing the app, sales & marketing app, or handling customer) 2. User Panel (access only by individual customer user free or paid) 3. Company Panel or can say Tenancy Panel (access only by paid customer who took subscription for registering company. ) Every customer who has access to Company panel will also have access to its user panel where they can do personal things. But vice versa is not true. So you can say not all customer users will have company tenant unless they have subscription to create one or they are invited by other company tenant owner to be its member. Further users who have access to Admin panel, they dont have any other panel. I have N:N multi-tenancy implemented using filament. I have single users table. I have Breeze package for authentication. In jetstream i found a concept of personal team which was mandatory for all users and got created automatically for all users but i dont have this design.
2 replies
FFilament
Created by Pritbor on 10/9/2024 in #❓┊help
Reusing Action arguments in Livewire Action
I'm using a custom edit/update action to change a category's status in Livewire, passing the category ID from the Blade file. My challenge is reusing the category instance retrieved in mountUsing() to fill the form, and again in ->action() to avoid fetching it by ID twice. I also want to avoid using public properties in Livewire.
public function updatePublishStatusAction(): Action
{
return Action::make('updatePublishStatus')
->label('Change Publish Status')
->mountUsing(function (Form $form, array $arguments) {
$category = BusinessCategory::find($arguments['categoryId']);
if ($category) {
$form->fill([
'status' => $category->status,
]);
}
})
->form([
Select::make('status')
->options(BusinessCategoryStatusEnum::class)
->default(BusinessCategoryStatusEnum::NOT_PUBLISHED),
])
->icon('heroicon-o-pencil-square')
->iconButton()
->size(ActionSize::ExtraSmall)
->action(function (array $data, array $arguments): void {
$category = BusinessCategory::find($arguments['categoryId']);
if ($category) {
$category->update([
'status' => $data['status'],
'updated_by' => auth()->id(),
'published_by' => $data['status'] === BusinessCategoryStatusEnum::PUBLISHED ? auth()->id() : null,
'published_at' => $data['status'] === BusinessCategoryStatusEnum::PUBLISHED ? now() : null,
]);
}

})
->modalHeading('Update Publish Status')
->modalSubmitActionLabel('Update Status')
->modalWidth(MaxWidth::Medium);
}
public function updatePublishStatusAction(): Action
{
return Action::make('updatePublishStatus')
->label('Change Publish Status')
->mountUsing(function (Form $form, array $arguments) {
$category = BusinessCategory::find($arguments['categoryId']);
if ($category) {
$form->fill([
'status' => $category->status,
]);
}
})
->form([
Select::make('status')
->options(BusinessCategoryStatusEnum::class)
->default(BusinessCategoryStatusEnum::NOT_PUBLISHED),
])
->icon('heroicon-o-pencil-square')
->iconButton()
->size(ActionSize::ExtraSmall)
->action(function (array $data, array $arguments): void {
$category = BusinessCategory::find($arguments['categoryId']);
if ($category) {
$category->update([
'status' => $data['status'],
'updated_by' => auth()->id(),
'published_by' => $data['status'] === BusinessCategoryStatusEnum::PUBLISHED ? auth()->id() : null,
'published_at' => $data['status'] === BusinessCategoryStatusEnum::PUBLISHED ? now() : null,
]);
}

})
->modalHeading('Update Publish Status')
->modalSubmitActionLabel('Update Status')
->modalWidth(MaxWidth::Medium);
}
2 replies
FFilament
Created by Pritbor on 8/27/2024 in #❓┊help
Conditional Eager loading issue
I am trying to eager load for table function in my MemberResource.php but I dont see table list after this. Since I have polymorphic realtionship, so i need to eager load conditionally and that is not working. Where i am going wrong. when I comment out conditional part of eager loading, I see table list.
public static function table(Table $table): Table
{
return $table
->modifyQueryUsing(function ($query){
$query->with([
'memberable',
'memberCreatedBy',
'memberUpdatedBy',
'platformTeamMemberAssignedBy',
'assignedPlatformTeamMembers',
]);

// Eager load specific relationships based on memberable_type
$query->when($query->getQuery()->where('memberable_type', Company::class)->exists(), function ($query) {
$query->with(['memberable.profile', 'memberable.profile.addresses']);
});

$query->when($query->getQuery()->where('memberable_type', User::class)->exists(), function ($query) {
$query->with('memberable.addresses');
});


return $query;

})
->columns([
public static function table(Table $table): Table
{
return $table
->modifyQueryUsing(function ($query){
$query->with([
'memberable',
'memberCreatedBy',
'memberUpdatedBy',
'platformTeamMemberAssignedBy',
'assignedPlatformTeamMembers',
]);

// Eager load specific relationships based on memberable_type
$query->when($query->getQuery()->where('memberable_type', Company::class)->exists(), function ($query) {
$query->with(['memberable.profile', 'memberable.profile.addresses']);
});

$query->when($query->getQuery()->where('memberable_type', User::class)->exists(), function ($query) {
$query->with('memberable.addresses');
});


return $query;

})
->columns([
2 replies
FFilament
Created by Pritbor on 8/25/2024 in #❓┊help
MorphToSelect is too slow
MorphToSelect for reading from large database is too slow. Is there any better alternative or any approach i can apply for chunking here. I have Member model which has MorphOne relationship with Company and User models. I need to select member in lets say LeadResource. Below is the code:-
Group::make()
->relationship('member')
->schema([
MorphToSelect::make('memberable')
->types([
MorphToSelect\Type::make(User::class)
->titleAttribute('name'),
MorphToSelect\Type::make(Company::class)
->titleAttribute('name')
])
->label('Member')
->required()
->searchable()
->preload()
->optionsLimit(5),
]),
Group::make()
->relationship('member')
->schema([
MorphToSelect::make('memberable')
->types([
MorphToSelect\Type::make(User::class)
->titleAttribute('name'),
MorphToSelect\Type::make(Company::class)
->titleAttribute('name')
])
->label('Member')
->required()
->searchable()
->preload()
->optionsLimit(5),
]),
6 replies
FFilament
Created by Pritbor on 8/22/2024 in #❓┊help
Table relationship sort error.
What is wrong in below code. I get error while sorting.
TextColumn::make('member.memberable.name')
->label('Company')
->wrap()
->searchable()
->sortable(),
TextColumn::make('member.memberable.name')
->label('Company')
->wrap()
->searchable()
->sortable(),
4 replies
FFilament
Created by Pritbor on 8/8/2024 in #❓┊help
How to get real-time validation error before clicking create/save button
Forms\Components\DateTimePicker::make('start_date')
->label('Start Date')
->required()
->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if ($value && Carbon::parse($value)->lt(Carbon::today())) {
$fail('The :attribute must be today or later.');
}
},
]),
Forms\Components\DateTimePicker::make('start_date')
->label('Start Date')
->required()
->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if ($value && Carbon::parse($value)->lt(Carbon::today())) {
$fail('The :attribute must be today or later.');
}
},
]),
4 replies
FFilament
Created by Pritbor on 8/7/2024 in #❓┊help
Issue with Dependent Select for MorphToSelect
In my CouponResource.php page, I am trying to have dependent select for 'assigned_to' field. I am experiencing very slow load while assigning 'assigned_to' field.
Group::make()
->relationship('advertisement')
->schema([
Group::make()
->relationship('member')
->schema([
MorphToSelect::make('memberable')
->types([
MorphToSelect\Type::make(Company::class)
->titleAttribute('name'),
MorphToSelect\Type::make(User::class)
->titleAttribute('name'),
])
->searchable()
->live()
->afterStateUpdated(function (Set $set) {
$set('assigned_to', null);
})
->required(),
]),
Forms\Components\Select::make('assigned_to')
->relationship(
name: 'assignedTo',
titleAttribute: 'name',
modifyQueryUsing: function (Builder $query, Get $get) {
$selectedMember = $get('member');
if ($selectedMember) {
if ($selectedMember['memberable_type'] === Company::class) {
$company = Company::with('users')->find($selectedMember['memberable_id']);
if ($company) {
$query->whereIn('id', $company->users->pluck('id'));
}
}
}
return $query;
}
)
->preload()
->required(),
])
->columns(2)
->columnSpanFull(),

Group::make()
->relationship('advertisement')
->schema([
Group::make()
->relationship('member')
->schema([
MorphToSelect::make('memberable')
->types([
MorphToSelect\Type::make(Company::class)
->titleAttribute('name'),
MorphToSelect\Type::make(User::class)
->titleAttribute('name'),
])
->searchable()
->live()
->afterStateUpdated(function (Set $set) {
$set('assigned_to', null);
})
->required(),
]),
Forms\Components\Select::make('assigned_to')
->relationship(
name: 'assignedTo',
titleAttribute: 'name',
modifyQueryUsing: function (Builder $query, Get $get) {
$selectedMember = $get('member');
if ($selectedMember) {
if ($selectedMember['memberable_type'] === Company::class) {
$company = Company::with('users')->find($selectedMember['memberable_id']);
if ($company) {
$query->whereIn('id', $company->users->pluck('id'));
}
}
}
return $query;
}
)
->preload()
->required(),
])
->columns(2)
->columnSpanFull(),

2 replies
FFilament
Created by Pritbor on 8/6/2024 in #❓┊help
Attach action error in RelationManager
I am getting below error during Select search while performing Attach action in header of Relationship manager.
Call to undefined method App\Models\Setting\BusinessCategory::businessCategories()
Call to undefined method App\Models\Setting\BusinessCategory::businessCategories()
I have BusinessCategory model with N:N relationship with itself. My model has parents() and children() methods. Currently it is only two level. And I using using simple Attach action in the Header.
7 replies
FFilament
Created by Pritbor on 6/20/2024 in #❓┊help
Using Filament Notification number in Frontpage notification icon
I just want to use the unread notification count to be used in bell icon present front end and when auth user clicks on it then is is routed dashbaord panel with notification sidebar open. Please help. I currently have filament dasbord with sliding bar notification panel in backend. How to proceed?
7 replies
FFilament
Created by Pritbor on 6/15/2024 in #❓┊help
How to use Grapejs in FilamentPHP
Has anyone tried Grapejs in FilamentPHP? I am aware of this plugin in Filament but it not enough documentation. https://filamentphp.com/plugins/dotswan-grapesjs .Any further help will be much appreaciated. I tried using this plugin in the field but I am getting all dump code. I
1 replies
FFilament
Created by Pritbor on 6/11/2024 in #❓┊help
Select form not retrieving data using getSearchResultsUsing()
I am using dependent selection using getSearchResultsUsing(). I am in Coupon record creation using handleRecordCreation(). And I am trying to select a user that belongs to a particular Member. In my implementation, A Member is a memberable either as an Individual user or a company. Here, I have to find all users belonging to a company memberable. My Company model has a method allUsers() that returns a collection. I am stuck in getting assigned to user.
3 replies
FFilament
Created by Pritbor on 5/28/2024 in #❓┊help
how to show a MorphOne table in filament Table?
I am struggling to access MorphOne relationship data in my table. I have Member model with MorphOne relationship with User and Company model. And I am trying display logo. But I am failing everytime. I use below code.
ImageColumn::make(function (Member $record) {
return $record->member_type === 'company' ? $record->memberable->profile->logo : $record->memberable->profile_photo_path;
})->size(200),
ImageColumn::make(function (Member $record) {
return $record->member_type === 'company' ? $record->memberable->profile->logo : $record->memberable->profile_photo_path;
})->size(200),
I get repeat error saying
Filament\Tables\Columns\Column::make(): Argument #1 ($name) must be of type string, Closure given, called in /var/www/html/app/Filament/Admin/Resources/MemberResource.php on line 103
Filament\Tables\Columns\Column::make(): Argument #1 ($name) must be of type string, Closure given, called in /var/www/html/app/Filament/Admin/Resources/MemberResource.php on line 103
.
16 replies
FFilament
Created by Pritbor on 5/17/2024 in #❓┊help
Adding Livewire in any Builder Block
How to add any livewire component in a Builder Block. I don't want to create blocks each livewire. This will be too much. So is hoping if i coult just copy paste my livewire in a TextArea field. But it is not working for me. I also tried using Livewire::make(Livewire::myclass) but it is again not working nd it hard coding the Liavewire every bock. How can i make it dynamic.
2 replies
FFilament
Created by Pritbor on 5/12/2024 in #❓┊help
Do we have any package for building navigation MenuManager
I am exploring any plugin for MenuManager. Please help. I dint find much. One plugin https://github.com/ryangjchandler/filament-navigation i found but that is not offically registerd in Filament latest version. And i tried beta version but I dint see any thing coming up in my panel. Like no navigation resource got created.
2 replies
FFilament
Created by Pritbor on 5/9/2024 in #❓┊help
How to use CreateAction while creating record
I want to use CreateAction using Modal for my record creation in resource manager. I dont want to use the existing form method in my main resource page. Unfortunately, I followed CreateAction document and applied in the CreateAction present in listing page. But it triggers the form present in the main resource page. Where I am missing?
5 replies
FFilament
Created by Pritbor on 5/9/2024 in #❓┊help
how to have Custom Select Layout during Create
No description
4 replies
FFilament
Created by Pritbor on 5/6/2024 in #❓┊help
Filament Shield not Generating Policy for Multi Guards
How to generate Policy using filament shield plugin if having multiple guards. I have two separate Authenticatble guards which i am using to login to two separate panels. Lets say Admin and User. Please help.
3 replies