Stormageddon, Dark Lord of All
Stormageddon, Dark Lord of All
Explore posts from servers
FFilament
Created by Stormageddon, Dark Lord of All 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 Stormageddon, Dark Lord of All 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 Stormageddon, Dark Lord of All 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 Stormageddon, Dark Lord of All 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 Stormageddon, Dark Lord of All 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
4 replies
FFilament
Created by Stormageddon, Dark Lord of All on 6/26/2024 in #❓┊help
import job failing continuously
No description
2 replies
FFilament
Created by Stormageddon, Dark Lord of All 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 Stormageddon, Dark Lord of All 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 Stormageddon, Dark Lord of All 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 Stormageddon, Dark Lord of All 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
FFilament
Created by Stormageddon, Dark Lord of All on 3/24/2024 in #❓┊help
Querying a distant relationship
in my filamentPHP dashboard I have a parcelResource. each parcel has one region, and a state has many regions, but I don't want the user to directly select the region, instead I want to narrow the list of regions based on the value of a selected state. I am assuming this is done somehow with hasOneThrough but I am not sure
3 replies
Mmalefashionadvice
Created by Stormageddon, Dark Lord of All on 1/13/2024 in #questions-and-advice
Which traditional piece to get?
No description
3 replies
FFilament
Created by Stormageddon, Dark Lord of All on 12/18/2023 in #❓┊help
What's the best way to test a function modularly
I have this computed text column, as you can see it's pretty complicated, so I want to add some tests, problem is that I've never wrote a test before. if possible I want to test this function without relying on the UI if you get what I mean, i.e. given this input what does the function output
TextColumn::make('ref')
->getStateUsing(
function (Model $record) {
$startOfYear = now()->startOfYear()->toDateTimeString();
$now = now()->toDateTimeString();
$invoices = Invoice::whereBetween('created_at', [$startOfYear, $now])
->get()
->sortBy('created_at');
if (! $invoices->first()) {
$calculatedId = 1;
} else {
$calculatedId = $record->id - $invoices->first()->id + 1;
}
$currentYear = (string) now()->year;
$state = $currentYear.'-'.sprintf('%03d', $calculatedId);

return $state;
})
TextColumn::make('ref')
->getStateUsing(
function (Model $record) {
$startOfYear = now()->startOfYear()->toDateTimeString();
$now = now()->toDateTimeString();
$invoices = Invoice::whereBetween('created_at', [$startOfYear, $now])
->get()
->sortBy('created_at');
if (! $invoices->first()) {
$calculatedId = 1;
} else {
$calculatedId = $record->id - $invoices->first()->id + 1;
}
$currentYear = (string) now()->year;
$state = $currentYear.'-'.sprintf('%03d', $calculatedId);

return $state;
})
2 replies
FFilament
Created by Stormageddon, Dark Lord of All on 11/29/2023 in #❓┊help
Filament (possibly laravel itself) using wrong mysql syntax
No description
5 replies
FFilament
Created by Stormageddon, Dark Lord of All on 11/21/2023 in #❓┊help
When to move from different panels to user permissions.
I have the following situation: there is an invoices resource. admins can view and edit all invoices users can view and create invoices assingned to them managers view all invoices but not create new ones. my current implementation is to create a new panel for every user type, I am wondering if implementing user roles is worth it at the moment or should I stick with the current implementation. If I should go with user permissions what plugin should I use / does filament have a permission system of it's own?
6 replies
FFilament
Created by Stormageddon, Dark Lord of All on 11/20/2023 in #❓┊help
Where can I find the main <head> tag in my filamentapp
I want to add PWA for my app and for that I need to add @LaravelPWA to my global head tag but I am not sure where to find that in the app
8 replies
FFilament
Created by Stormageddon, Dark Lord of All on 11/18/2023 in #❓┊help
"Are you sure?" dialog when editing certain fields
there is a field in my form that is highly dangerous. it's only available to super admins but i still want to make sure it only gets updated when needed I want to show a simple are you sure model when someone attempts to save the form and they changed tha field.
2 replies
FFilament
Created by Stormageddon, Dark Lord of All on 11/18/2023 in #❓┊help
Why are resources added to my admin panel automatically?
I created an admin panel, than created an invoice resource, but crucially, I didn't include it in the pages array yet it was added automatically, why is that?
4 replies
FFilament
Created by Stormageddon, Dark Lord of All on 11/18/2023 in #❓┊help
Make a column smaller (sort of an index)
No description
5 replies
FFilament
Created by Stormageddon, Dark Lord of All on 11/18/2023 in #❓┊help
Referencing a field
I want to dynamically set a field's columnSpan. I know that's doable because the columnSpan accepts a closure but I need to reference another field to figure out the column span. ie. set columnSpan is 2 if field 1 is visible otherwise set it to 1
6 replies