King Dice
King Dice
Explore posts from servers
FFilament
Created by King Dice on 7/25/2024 in #❓┊help
Select input value not being set
No description
6 replies
FFilament
Created by King Dice on 7/18/2024 in #❓┊help
Only last group is displaying
Hi, If I have multiple groups set in my table, only the last one will be displayed in the select. this is happening across my entire project. for instance, here, only the type column will be available to group with:
->groups([
Group::make('state.name')->label('Governorat'),
Group::make('type'),
])
->groups([
Group::make('state.name')->label('Governorat'),
Group::make('type'),
])
the same thing if I use simple string groups:
->groups([
'type',
'state.name'
])
->groups([
'type',
'state.name'
])
in this case only state.name will show up in the select menu because it's the last one.
2 replies
FFilament
Created by King Dice on 7/17/2024 in #❓┊help
Summarize course revenue
No description
4 replies
FFilament
Created by King Dice on 7/15/2024 in #❓┊help
Sum relationship
I have a User model and a Course model. with a relationship between them, this relationship is defined as "enrollment" (enrollment is basically the pivot table of the relationship) I have made a filament resource for enrollments. I want to get the sum of the costs of all courses If I use the default Sum, I get the unique sum like so:
enrollments table:
id | user_id | course_id|
1 | 1 | 32 |
2 | 1 | 36 |
3 | 2 | 32 |
enrollments table:
id | user_id | course_id|
1 | 1 | 32 |
2 | 1 | 36 |
3 | 2 | 32 |
this currently returns the following cost of course 32 + cost of course 36. but what I want is to return cost of course 32 + cost of course 36 + cost of course 32
2 replies
FFilament
Created by King Dice on 7/11/2024 in #❓┊help
Change ToggleButtons Selected Color
Hi, very simpleQuestion. How can I change the selected button's color in a toggle button? I don't want to set the color for every option individually, just the selected one.
5 replies
FFilament
Created by King Dice on 7/11/2024 in #❓┊help
Filter values keep existing out of nowhere.
No description
7 replies
FFilament
Created by King Dice on 7/10/2024 in #❓┊help
Brainstorming ways to solve this problem
Kinda unrelated to filament, but I am going to use this feature in a filament panel so I might as well just ask here: I am looking for a way to generate PDFs based on (1) data from my model and (2) a pre-made design. kinda like how udemy and other course sites generate custom certificates. Here is an idea I just came up with: somehow make a bunch of templates in html & css with some parts of it being customizable then allow the user to customize the template (e.g. change the logo, color palette, etc..) and finally export it to pdf. but I have no idea how that would work in practice. if anyone has any better ideas/ something similar implemented in laravel or filament / a totally different idea let me know!
14 replies
FFilament
Created by King Dice on 7/8/2024 in #❓┊help
How to add the owner record's name to export CSV
Hi, I have an export action, it is used on a relation manager. I simply want to include the name of the owner record somewhere in the exported document, it could be set as the value of a column or included in the csv header. it just has to be included somewhere. I couldn't figure it out on my own thank you in advance
2 replies
FFilament
Created by King Dice on 7/6/2024 in #❓┊help
disable detaching items only in multi-select
Hi, I have a multi select and I want to disable the detachment of elements from this multi select based on some condition. I can't use ->disabled though cause I still need the addition of new elements to be possible
2 replies
FFilament
Created by King Dice on 7/4/2024 in #❓┊help
ambiguous column name: id
Hello, I have an exporter on my User relation manager. sometimes when I export, it fails with the following error:
General error: 1 ambiguous column name: id (Connection: sqlite, SQL:
General error: 1 ambiguous column name: id (Connection: sqlite, SQL:
select distinct "users"."id" from "users" inner join "course_user" on "users"."id" = "course_user"."user_id" where "course_user"."course_id" = 1 order by "users"."id" asc, "id" asc limit 1000)
select distinct "users"."id" from "users" inner join "course_user" on "users"."id" = "course_user"."user_id" where "course_user"."course_id" = 1 order by "users"."id" asc, "id" asc limit 1000)
5 replies
FFilament
Created by King Dice on 6/30/2024 in #❓┊help
Empty hidden fields
I have two columns in my table hours and semesters. both are nullable. in my form, I have a checkbox, it's value decides whether to show the hours or the semesters input using the ->hidden method now I don't want both semesters and hours to be set at the same time, so for example if horus is shown I want to make sure semesters is null when saving the form and vice-verca
4 replies
FFilament
Created by King Dice on 6/30/2024 in #❓┊help
Getting weather a field is disabled or not
I have a simple question: how can I access whether a field is disabled or not. I need this information inside a callback function.
6 replies
FFilament
Created by King Dice on 6/29/2024 in #❓┊help
Best way to handle bulk-attaching models
I have a courses model and a users model, with a many-to-many relationship between the 2. I need a way to attach many users at once to a certain course. The users that need to be attached are stored in a csv with their unique IDs. Here are a few options I came up with: - using a CSV importer: since I have a csv I could simply import it and associate that way. the problem with this method is that configuring an importer is tedious and error prone - here is another idea I came up with that I am not sure is possible in filament or not: having an action that opens a modal with an input field, this input field would take multiple space seperated user ids and then inserts them into the pivot table. this idea sounds good but I am not sure how to implement it if someone could guide me on how to implement the second option or has a better idea let me know!
4 replies
FFilament
Created by King Dice on 6/28/2024 in #❓┊help
resource authorization simple question
Hey in my app I have a schools resource, super admins can make,view, edit and delete any school. regular admins can create,view, edit and delete only schools that belong to one of their regions. Initially I was using the following on the schools resource on the regular admin panel:
->modifyQueryUsing(function (Builder $query) {
return $query->whereHas('admin', function (Builder $filter) {
$filter->where('id', auth()->id());
});
->modifyQueryUsing(function (Builder $query) {
return $query->whereHas('admin', function (Builder $filter) {
$filter->where('id', auth()->id());
});
This worked but I incorrectly assumed that this query change would be applied to every query belonging to that resource which means that regular admins would not be able to access schools that don't belong to them. I tried to edit the URL to access one of those records assuming it would return an 403 error but it worked. so modifyQueryUsing only affects the list view now I understand that for this type of authorisation work I need to use model policies but in my case the policy will be practically the same for view, viewAny, update and the rest of the policy methods, so is there a way to define this policy once and for all like I was doing with the modifyQueryUsing, I hope that made sense
2 replies
FFilament
Created by King Dice on 6/28/2024 in #❓┊help
How to download failed rows?
Hi, I have an import action when I click on the link to download the failed rows, I get redirected to http://localhost:8000/filament/imports/2/failed-rows/download and I am met with a Route [login] not defined. error
5 replies
FFilament
Created by King Dice on 6/26/2024 in #❓┊help
import job failing continuously
No description
2 replies
FFilament
Created by King Dice on 6/26/2024 in #❓┊help
Import Model still trying to use user_id despite specifying a different model
Hiya, I am using the import action, I have two Authenticatable models User and Admin, I changed the column name to admin_id on the imports migration but it still tries to use user_id
4 replies
FFilament
Created by King Dice on 6/26/2024 in #❓┊help
Modify Query Using nested relationship
Hi, I have an institution resource, every institution belongs to a state and every state belongs to an admin. admin ----has many---> states ---has many----> institutions I want to only show the institutions that belong indirecly to the currently logged in admin, this is what I attempted but it didn't work:
->modifyQueryUsing(function (Builder $query) {
return $query->withWhereHas('state.admin', function (Builder $filter) {
$filter->where('id', auth()->id());
});
->modifyQueryUsing(function (Builder $query) {
return $query->withWhereHas('state.admin', function (Builder $filter) {
$filter->where('id', auth()->id());
});
2 replies
FFilament
Created by King Dice on 6/25/2024 in #❓┊help
Manually handling many-to-many relationships
Hi, I have a many to many relationship between my Major and my Course models. in my Course resource I used to have
Select::make('majors')
->relationship('majors', 'name')
->multiple()
->required()
Select::make('majors')
->relationship('majors', 'name')
->multiple()
->required()
I wanted to filter the list of majors available in this select based on the value of another column, I came up with this solution
Forms\Components\Select::make('type')
->options(InstitutionType::class)
->live()
->afterStateUpdated(fn (FilamentSet $set) => $set('majors', null) )
->required(),
Select::make('majors')
->options(fn (Get $get) => Major::where('type', '=', $get('type'))->get()->pluck('name', 'id'))
->multiple()
->required(),
Forms\Components\Select::make('type')
->options(InstitutionType::class)
->live()
->afterStateUpdated(fn (FilamentSet $set) => $set('majors', null) )
->required(),
Select::make('majors')
->options(fn (Get $get) => Major::where('type', '=', $get('type'))->get()->pluck('name', 'id'))
->multiple()
->required(),
but without the relationship method the form cannot be submitted properly, because filament no longer knows how to handle my majors and institutions relationship
4 replies
FFilament
Created by King Dice on 5/12/2024 in #❓┊help
csv import creating data in multiple models
Hello, let's say I have a user and a course. a user can have many courses and I have a csv with the following data. userId, userName, courseName, CourseDescription. in my database the relation between the courses and the user is made through the userId, it's a one-to-many relationship I am in the courses view in filament which has a csv import button, if I import this csv I am assuming it will be able to fill in the userId, courseName and courseDescription. but my question is: if the userId doesn't exist in the users table, can filament also create this new user?
2 replies