schwartzmj
schwartzmj
Explore posts from servers
CDCloudflare Developers
Created by schwartzmj on 5/20/2024 in #pages-help
404 cached in Cloudflare?
I had this issue a while back, but was too busy to reach out and figure out what exactly was going on. Essentially I have a SvelteKit app that may have a file like index.338f2fbe.js We had users reporting that the website was broken for them — after debugging we found that this file was 404ing (amongst 1-2 others) — but only for some users. After a bunch of debugging, my only reasoning was that somewhere down the line, Cloudflare had an issue where this file was unavailable and responded with a 404, then this 404 was cached to our users and their browsers never requested the file again, instead using the cached response. This was tested by finding a random device that had this error and clearing the browser's cache. To solve it for all users, I just changed the project's code so that the hash got changed at build. But I'm wondering what actually happened here and how it can be avoided.
1 replies
CC#
Created by schwartzmj on 4/26/2024 in #help
URL Parameters and/or data loading in layout files
Assume I have some pages as such: - /websites/{WebsiteId:int} - /websites/{WebsiteId:int}/faqs - /websites/{WebsiteId:int}/testimonials - /websites/{WebsiteId:int}/services They all use the same layout for navigation, as such:
@using WebsiteBuilder.Components.Layout
@inherits LayoutComponentBase
@layout MainLayout

<div class="container">
<nav>
<ul>
<li><a href="/websites/@WebsiteId">Details</a></li>
<li><a href="/websites/@WebsiteId/faqs">FAQs</a></li>
<li><a href="/websites/@WebsiteId/testimonials">Testimonials</a></li>
<li><a href="/websites/@WebsiteId/services">Services</a></li>
</ul>
</nav>
@Body
</div>

@code {
[Parameter] public int WebsiteId { get; set; }
}
@using WebsiteBuilder.Components.Layout
@inherits LayoutComponentBase
@layout MainLayout

<div class="container">
<nav>
<ul>
<li><a href="/websites/@WebsiteId">Details</a></li>
<li><a href="/websites/@WebsiteId/faqs">FAQs</a></li>
<li><a href="/websites/@WebsiteId/testimonials">Testimonials</a></li>
<li><a href="/websites/@WebsiteId/services">Services</a></li>
</ul>
</nav>
@Body
</div>

@code {
[Parameter] public int WebsiteId { get; set; }
}
How do I get the @WebsiteId URL parameter "passed up" to the Layout or resolved from the URL? Is there anything built in to ASP.NET Core 8 for this?
13 replies
FFilament
Created by schwartzmj on 4/25/2024 in #❓┊help
Subdomain / Domain based routing w/ Multitenancy. 419 Page Expired
I'm testing out Filament with Spatie's Multitenancy package. The tenant is decided based on the current request's domain or subdomain. If it's a subdomain of the app's TLD then we use the tenant's subdomain, else we use the domain. So far, I'm only testing with subdomains. I'm able to login and get redirected to the proper tenant & subdomain (though I have to login twice for some reason). But, anytime I try to edit a resource I get a Page Expired error. Changing SESSION_DOMAIN from null to localhost or *.localhost appears to cause more of these errors everywhere. Keeping it null only causes errors on form submissions. Any ideas? Am I missing something? Google hasn't been too helpful for me.
11 replies
CC#
Created by schwartzmj on 4/16/2024 in #help
Redirect after form POST Blazor Static
Am I not able to have a statically rendered Blazor @code block return a redirect? e.g.:
c#
@code {

private sealed class InputModel
{
[Required]
[MaxLength(50)] public string Name { get; set; } = "";
[Required]
[MaxLength(300)]
public string Description { get; set; } = "";
}

[SupplyParameterFromForm] private InputModel Input { get; set; } = new();

public async Task CreateWebsite()
{
try
{
var website = new Website
{
Name = Input.Name,
Description = Input.Description
};
DbContext.Websites.Add(website);
await DbContext.SaveChangesAsync();
}
catch (Exception e)
{
Console.WriteLine(e);
}

}
}
c#
@code {

private sealed class InputModel
{
[Required]
[MaxLength(50)] public string Name { get; set; } = "";
[Required]
[MaxLength(300)]
public string Description { get; set; } = "";
}

[SupplyParameterFromForm] private InputModel Input { get; set; } = new();

public async Task CreateWebsite()
{
try
{
var website = new Website
{
Name = Input.Name,
Description = Input.Description
};
DbContext.Websites.Add(website);
await DbContext.SaveChangesAsync();
}
catch (Exception e)
{
Console.WriteLine(e);
}

}
}
14 replies
CC#
Created by schwartzmj on 4/16/2024 in #help
.NET Core `dotnet watch run` on MacOS
For me, dotnet watch run frequently needs to be restarted because it stops seeing changes. Does anybody else have this issue? It happens frequently enough that I'm not sure I can even use it. e.g. I'm getting some .NET error and it won't compile. Restart it and it works. Or trying to debug something and wondering why it isn't working — turns out the code is actually correct and .NET just needed to be restarted because it isn't seeing my changes.
2 replies
CDCloudflare Developers
Created by schwartzmj on 4/10/2024 in #general-help
Bypassing bot protection
I'm writing a CLI tool that crawls websites we make to check for broken links and other items. Naturally, Cloudflare sees this traffic, considers it a bot and blocks it after a few requests (usually). Can I bypass this protection with a header and API key or something along those lines? I'd prefer not having to allow an IP because I want the tooling to work wherever I am.
9 replies
FFilament
Created by schwartzmj on 4/2/2024 in #❓┊help
Media Picker field type
I'm currently using Spatie's laravel-medialibrary package. I was wondering if there are any field types where you can also choose an image from previously uploaded images instead of always uploading a new one.
5 replies
FFilament
Created by schwartzmj on 3/26/2024 in #❓┊help
Custom Field CSS
If I want to make one or two one-off custom fields, and I want to write my own Tailwind in the blade file, how do I get that CSS into filament? Do I have to make a theme?
3 replies
FFilament
Created by schwartzmj on 3/13/2024 in #❓┊help
Blade components outside of Filament
Am I not able to do something like <x-filament::button>Test</x-filament::button> in my Laravel app (and not in Filament)? Are there styles I need to require?
3 replies
FFilament
Created by schwartzmj on 2/21/2024 in #❓┊help
Does Filament play well with laravel-data?
I'm looking at creating a form that doesn't tie directly to an Eloquent model. Instead, when the form is validated and submitted I manually create model(s). I considered using laravel-data as the "model" for a Filament form for this. Is that a good path to take?
4 replies
FFilament
Created by schwartzmj on 2/19/2024 in #❓┊help
Refresh parent on relationship manager update
Is there an easy way to refresh the parent model's data whenever something in the relationship manager happens? e.g. I have an "Order" model with "LineItems" and i need to update the Order Total when I delete or change a line item
6 replies
FFilament
Created by schwartzmj on 2/15/2024 in #❓┊help
Reordering repeater items
https://filamentphp.com/docs/3.x/forms/fields/repeater#reordering-items Am I going crazy? Isn't there a way to tell it what column the "order" should save to?
12 replies
FFilament
Created by schwartzmj on 2/14/2024 in #❓┊help
Can’t get Pivot table logic to work
I have a pretty straightforward use case, but the implementation in Filament is throwing me for a loop. Imagine Products that have many Options that in turn have many values (Size w/ SM, MD, LG and Color w/ Red, Blue). This part is straightfoward. The user creates Options and in turn the values. Now the user needs to create a ProductVariant. They need to select one of each ProductOptionValue (e.g SM & Red), but should not be able to select e.g. SM & LG. In other words, they have to select one option from each. I've tried so many things I'm not sure if it's even worth pasting it all in here as it has become a mess, but nothing seems to be working. Am I better off just creating a custom page, form, or field type?
1 replies
FFilament
Created by schwartzmj on 2/14/2024 in #❓┊help
Very stuck on BelongsToMany / Pivot table with a restriction
I have a pretty straightforward use case, but the implementation in Filament is throwing me for a loop. Imagine Products that have many Options that in turn have many values (Size w/ SM, MD, LG and Color w/ Red, Blue). This part is straightfoward. The user creates Options and in turn the values. Now the user needs to create a ProductVariant. They need to select one of each ProductOptionValue (e.g SM & Red), but should not be able to select e.g. SM & LG. In other words, they have to select one option from each. I've tried so many things I'm not sure if it's even worth pasting it all in here as it has become a mess, but nothing seems to be working. Am I better off just creating a custom page, form, or field type?
1 replies
FFilament
Created by schwartzmj on 2/13/2024 in #❓┊help
"Saving data to a BelongsTo relationship" nullable foreign key workaround
Regarding https://filamentphp.com/docs/3.x/forms/advanced#saving-data-to-a-belongsto-relationship Is there any way around this? I'd prefer not to make my foreign keys nullable. Could I create a custom Livewire component or page for creating a new resource? I could then handle the logic in there (create parent, attach relation).
2 replies
FFilament
Created by schwartzmj on 2/6/2024 in #❓┊help
Pre-populating form and saving to pivot
4 tables and one pivot table: Products, Product_Options, Product_Option_Values, and Product_Variants. The pivot table essentially just joins the 3 latter tables with unique constraints. I've made a custom pivot model for this and the relationship for the variant is selectedOptions which you'll see below. The user creates a product, then creates its "Product Options" with available "Values". For example, Size: SM, MD, LG and Color: Red, Blue This works fine. The issue I'm encountering is when the user goes to create a new Product Variant (via a relation manage on the Product), I want to loop through all available Product Options and have them select a Value. I've tried a number of things but none of it seems to be working correctly. This is the gist of one route I went:
2 replies
FFilament
Created by schwartzmj on 1/27/2024 in #❓┊help
Confirmation on my approach for nested resources
I have two models, Fundraiser and Product. Fundraisers have Products. On a Fundraiser page, I want to list all products. Clicking one should go to e.g. fundraisers/6/products/2 and have breadcrumbs to go "back" to the fundraiser. It sounds like I have to create a RelationManager (to get the table on the fundraiser page), then also create a Relation Page (for the page), then customize the actions on the RelationManager table to link to the Relation Page. Is that accurate or am I missing something else? I don't want modals for this Product relation. These products are going to have their own nested relation (Variants, etc) and that sounds messy / not ideal.
3 replies
FFilament
Created by schwartzmj on 1/24/2024 in #❓┊help
Simplifying computed field
I'm currently using a Placeholder field that calls $get on 8 fields to calculate a new value. This also involves calling ->live() on each field. Are there any shortcuts to this that I'm missing? i.e. getting all data values at once or a mirror of the current state of the $record? As a secondary, related question: I may have to create a public version of this form as well, and I'm not sure yet, but it might be easier for me to just create a livewire component myself for that due to some very specific UI constraints. Is it simple to juse re-use that Livewire component inside the Filament admin panel in place of the Create & Edit forms or should I just manage an "admin" version of this form as well as the public-facing version?
1 replies
FFilament
Created by schwartzmj on 1/23/2024 in #❓┊help
Using Tailwind in a custom field
My custom field(s) live in resources/views/filament/forms/components. I'd like to use Tailwind here. The issue appears to be that Filament will not use my app's CSS file. If I force Filament to load this CSS file, I notice that miscellaneous Filament styles in the admin panel get overridden. Any best practices here?
2 replies
FFilament
Created by schwartzmj on 12/22/2023 in #❓┊help
Custom Field - load data for the view
I initially thought a custom field was just a base livewire component. It appears I can't run Livewire lifecycle methods in the component though. How can I load some data from my database to render in the view for a custom field?
7 replies