karpadiem
karpadiem
FFilament
Created by karpadiem on 9/19/2024 in #❓┊help
CanAccessPanel logic causing 403 error for livewire.update on Tenant Registration Form
That would be great! I’ll clean some stuff up and send it your way!
18 replies
FFilament
Created by karpadiem on 9/19/2024 in #❓┊help
CanAccessPanel logic causing 403 error for livewire.update on Tenant Registration Form
They create their own tenants
18 replies
FFilament
Created by karpadiem on 9/19/2024 in #❓┊help
CanAccessPanel logic causing 403 error for livewire.update on Tenant Registration Form
Access to particular tenant is controlled elsewhere right? This is just if the user can access the particular panel or not? I did it this way because besides the two user types above (member of an company and employees of the Saas [admins]) there is a third user type and panel of customer. Based on your feedback, sounds like i have three options? - Leave it as is with the livewire.update route override (assuming this is not security risk) - Move my tenant (company) registration outside of the company panel - Remove the check for accessing the company panel and handle rerouting "customers" a different way. Does that sound right?
18 replies
FFilament
Created by karpadiem on 9/19/2024 in #❓┊help
CanAccessPanel logic causing 403 error for livewire.update on Tenant Registration Form
I think the TLDR here is: How do I use canAccessPanel() on the user model and tenantRegistration() on the panel service provider together.
18 replies
FFilament
Created by karpadiem on 9/19/2024 in #❓┊help
CanAccessPanel logic causing 403 error for livewire.update on Tenant Registration Form
After lots of trial and error. It's failing when the route is a livewire.update request orignating from the company panel when the user is not yet associated with a company (my tenant model). This bit of code added to anAccessCompanyPanel() fixes it, but I worry that's not the approprate way to handle it. Does this present a security risk?
/if route is livewire.update
if ($route && $route->getName() && $route->getName() === 'livewire.update') {
\Log::info('User is accessing livewire message');
return true;
}
/if route is livewire.update
if ($route && $route->getName() && $route->getName() === 'livewire.update') {
\Log::info('User is accessing livewire message');
return true;
}
18 replies
FFilament
Created by karpadiem on 9/19/2024 in #❓┊help
CanAccessPanel logic causing 403 error for livewire.update on Tenant Registration Form
Oh? Im not sure i see where that is happening. That would cause a 403 error on a livewire request?
18 replies
FFilament
Created by karpadiem on 9/19/2024 in #❓┊help
CanAccessPanel logic causing 403 error for livewire.update on Tenant Registration Form
The only thing i can think to do to fix it (and it does) is add
//if route is livewire.update
if ($route && $route->getName() && $route->getName() === 'livewire.update') {
\Log::info('User is accessing livewire message');
return true;
}
//if route is livewire.update
if ($route && $route->getName() && $route->getName() === 'livewire.update') {
\Log::info('User is accessing livewire message');
return true;
}
But i worry that will create some sort of security issue. Am i missing something obvious?
18 replies
FFilament
Created by karpadiem on 9/19/2024 in #❓┊help
CanAccessPanel logic causing 403 error for livewire.update on Tenant Registration Form
public function canAccessCompanyPanel(): bool
{

$route = request()->route();

if ($route && $route->getName()) {
\Log::info('Route name:', ['route' => $route->getName()]);
} else {
\Log::info('No route name available');
}

// Allow access to specific routes
if ($route && in_array($route->getName(), [
'filament.company.tenant.registration',
'filament.company.auth.logout',
'filament.company.auth.login',
])) {
\Log::info('User is accessing an allowed route');
return true;
}
public function canAccessCompanyPanel(): bool
{

$route = request()->route();

if ($route && $route->getName()) {
\Log::info('Route name:', ['route' => $route->getName()]);
} else {
\Log::info('No route name available');
}

// Allow access to specific routes
if ($route && in_array($route->getName(), [
'filament.company.tenant.registration',
'filament.company.auth.logout',
'filament.company.auth.login',
])) {
\Log::info('User is accessing an allowed route');
return true;
}
This allowed the user to access these pages. However, shortly after accessing the page, the first livewire.update request happens and a 403 error is thrown.
18 replies
FFilament
Created by karpadiem on 7/31/2024 in #❓┊help
Table Column Relationship Sum, Avg, Max, Min, ext being ignored
No description
11 replies
FFilament
Created by karpadiem on 7/31/2024 in #❓┊help
Table Column Relationship Sum, Avg, Max, Min, ext being ignored
Trying it three different ways,
//No Aggregating
Tables\Columns\TextColumn::make('locationInventory.quantity_in_stock')
->label('In Stock'),
//documentation way
Tables\Columns\TextColumn::make('quantity_in_stock_sum')
->label('In Stock')
->sum('locationInventory', 'quantity_in_stock'),
// working solution
Tables\Columns\TextColumn::make('quantity_in_stock')
->label('In Stock')
->sum('locationInventory', 'quantity_in_stock'),
//No Aggregating
Tables\Columns\TextColumn::make('locationInventory.quantity_in_stock')
->label('In Stock'),
//documentation way
Tables\Columns\TextColumn::make('quantity_in_stock_sum')
->label('In Stock')
->sum('locationInventory', 'quantity_in_stock'),
// working solution
Tables\Columns\TextColumn::make('quantity_in_stock')
->label('In Stock')
->sum('locationInventory', 'quantity_in_stock'),
11 replies
FFilament
Created by karpadiem on 7/31/2024 in #❓┊help
Table Column Relationship Sum, Avg, Max, Min, ext being ignored
@Dennis Koch I’m definitely reading in the documentation that your suggestion should be correct. I guess I’m worried something else is wrong since dropping the “_sum” made it work.
11 replies
FFilament
Created by karpadiem on 7/31/2024 in #❓┊help
Table Column Relationship Sum, Avg, Max, Min, ext being ignored
changing it to quantity_in_stock_sum made the column blank. But changing it to quantity_in_stock has it properly summing the values. Thanks for your help!
11 replies
FFilament
Created by karpadiem on 7/31/2024 in #❓┊help
Table Column Relationship Sum, Avg, Max, Min, ext being ignored
No description
11 replies
FFilament
Created by karpadiem on 7/1/2024 in #❓┊help
Creating new entries for multiple recourses in a single form
Ok, that's fair! As long as that is the expected behaviour I'll keep tinkering with what I got. Thanks!
13 replies
FFilament
Created by karpadiem on 7/1/2024 in #❓┊help
Creating new entries for multiple recourses in a single form
Follow up question, ContactResource::formShcema()) has a repeater for email addresses. It's using the Contact Model's email_addresses relationship. This works properly on the Contact Creation page, edit page, view page, as well as the employee view page and edit page. However, the values of the repeater seem to be trashed in this create employee wizard. Are repeaters nested in a relationship supported when creating a new entry, or am i doing something else wrong?
13 replies
FFilament
Created by karpadiem on 7/1/2024 in #❓┊help
Creating new entries for multiple recourses in a single form
Ok, I seem to be getting closer. I think i was expecting to have the full data show in the dd(data) of handleRecordCreation(array $data) and was debugging that way. I see how that the employee record would be created first, and then the contact record.
13 replies
FFilament
Created by karpadiem on 7/1/2024 in #❓┊help
Creating new entries for multiple recourses in a single form
I guess this is where Im struggeling. How do I properly assign the relationship() to all fields in ->schema(ContactResource::formShcema()) ? Is it possible to assign a relationship to a Group, Fieldset, or Section?
13 replies
FFilament
Created by karpadiem on 7/1/2024 in #❓┊help
Creating new entries for multiple recourses in a single form
I just feel like Im not understanding the proper way to do something here and want to make sure I get on the right path before hammering it much harder. 🙂 Thanks!
13 replies
FFilament
Created by karpadiem on 7/1/2024 in #❓┊help
Creating new entries for multiple recourses in a single form
However, if add dd($data); to protected function handleRecordCreation(array $data):Model None of the information from that part of the form is there.
array:7 [▼ // app/Filament/Company/Resources/EmployeeResource/Pages/CreateEmployee.php:78
"contact_id" => null
"employee_number" => null
"start_date" => null
"end_date" => null
"status" => "terminated"
"seasonal" => "1"
"part_time" => "0"
]
array:7 [▼ // app/Filament/Company/Resources/EmployeeResource/Pages/CreateEmployee.php:78
"contact_id" => null
"employee_number" => null
"start_date" => null
"end_date" => null
"status" => "terminated"
"seasonal" => "1"
"part_time" => "0"
]
However, if i make the whole step use ContactResource::formSchema() it does pass the information i want, except not packaged in a array of 'contact.fields'. This option also keeps me from using a select that would allow the user to pick an existing contact.
array:11 [▼ // app/Filament/Company/Resources/EmployeeResource/Pages/CreateEmployee.php:40
"first_name" => "sdfsd"
"middle_name" => null
"last_name" => "sdfsd"
"nick_name" => null
"preferred_name" => null
"employee_number" => null
"start_date" => null
"end_date" => null
"status" => "active"
"seasonal" => "0"
"part_time" => "0"
]
array:11 [▼ // app/Filament/Company/Resources/EmployeeResource/Pages/CreateEmployee.php:40
"first_name" => "sdfsd"
"middle_name" => null
"last_name" => "sdfsd"
"nick_name" => null
"preferred_name" => null
"employee_number" => null
"start_date" => null
"end_date" => null
"status" => "active"
"seasonal" => "0"
"part_time" => "0"
]
13 replies
FFilament
Created by karpadiem on 7/1/2024 in #❓┊help
Creating new entries for multiple recourses in a single form
Below is some of my work so far.
Step::make('Personal Information')
->description('Enter the employee\'s personal information, or attach to an existing contact in the system',)
->schema([
//select to choose an existing contact.
Select::make('contact_id')
->label('Contact')
//todo: refactor to exclude any contacts that already have an employee relationship
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->first_name} {$record->last_name}")
->searchable()
->placeholder("New Contact")
->preload()
->live()
->native(false),
//embed edit form from contact resource

//reuse the contact resource form schema
Fieldset::make()
->relationship('contact')
//reuse the contact resource form schema
->schema(
ContactResource::formSchema()
)
->live()
->hidden(function(Get $get, $operation){

//get the current operation
//if page is edit show the form
if($get('contact_id') !== null){
return true;
}else{
return false;
}
})

]),
Step::make('Personal Information')
->description('Enter the employee\'s personal information, or attach to an existing contact in the system',)
->schema([
//select to choose an existing contact.
Select::make('contact_id')
->label('Contact')
//todo: refactor to exclude any contacts that already have an employee relationship
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->first_name} {$record->last_name}")
->searchable()
->placeholder("New Contact")
->preload()
->live()
->native(false),
//embed edit form from contact resource

//reuse the contact resource form schema
Fieldset::make()
->relationship('contact')
//reuse the contact resource form schema
->schema(
ContactResource::formSchema()
)
->live()
->hidden(function(Get $get, $operation){

//get the current operation
//if page is edit show the form
if($get('contact_id') !== null){
return true;
}else{
return false;
}
})

]),
As far as an interface, this is working exactly how I would like it.
13 replies