Arjen
Arjen
FFilament
Created by Arjen on 1/25/2024 in #❓┊help
Table column loses data when sorting by relationship
I have the following relation Booking -> HasMany -> Dayparts where Dayparts has a field date. I want to sort courses by the first child in Dayparts and while the code for that sorts the items in the table correctly, the data in the sorted column in the table just disappears. When the table is not sorted, the date is showing correctly. Any idea what I'm doing wrong? This is the table column in the BookingResource:
Tables\Columns\TextColumn::make('dayparts.0.date')
->label('Datum')
->date('d-m-Y')
->sortable(
query: fn ($query, $direction) => $query
->join('dayparts', function ($join) {
$join->on('dayparts.booking_id', '=', 'bookings.id')
->on('dayparts.id', DB::raw("(SELECT min(id) FROM dayparts WHERE dayparts.booking_id = bookings.id)"));
})
->orderBy('date', $direction)
),
Tables\Columns\TextColumn::make('dayparts.0.date')
->label('Datum')
->date('d-m-Y')
->sortable(
query: fn ($query, $direction) => $query
->join('dayparts', function ($join) {
$join->on('dayparts.booking_id', '=', 'bookings.id')
->on('dayparts.id', DB::raw("(SELECT min(id) FROM dayparts WHERE dayparts.booking_id = bookings.id)"));
})
->orderBy('date', $direction)
),
I tried changing 'dayparts.0.date' to 'date' as well, but that changes nothing.
3 replies
FFilament
Created by Arjen on 12/1/2023 in #❓┊help
Convert Filament::registerScripts
Hi, how do I convert the following piece of code from v2 to v3 FilamentAsset? I want to use the compiled code at public/build/assets/app-fdfe8a8c.js (for example) instead of the source in resources/js/app.js
Filament::serving(function () {
Filament::registerScripts([
app(Vite::class)('resources/js/app.js')
], true);
});
Filament::serving(function () {
Filament::registerScripts([
app(Vite::class)('resources/js/app.js')
], true);
});
5 replies
FFilament
Created by Arjen on 10/11/2023 in #❓┊help
Setting searchable select field to null not working
No description
4 replies
FFilament
Created by Arjen on 9/30/2023 in #❓┊help
Best way to include script
Hi, I've registered a custom script like this:
FilamentAsset::register([
Js::make('google-maps')->html(new HtmlString('
<script>
(g => {
var h, a, k, p = "The Google Maps JavaScript API",
c = "google",
l = "importLibrary",
q = "__ib__",
m = document,
b = window;
b = b[c] || (b[c] = {});
var d = b.maps || (b.maps = {}),
r = new Set,
e = new URLSearchParams,
u = () => h || (h = new Promise(async (f, n) => {
await (a = m.createElement("script"));
e.set("libraries", [...r] + "");
for (k in g) e.set(k.replace(/[A-Z]/g, t => "_" + t[0].toLowerCase()), g[k]);
e.set("callback", c + ".maps." + q);
a.src = `https://maps.${c}apis.com/maps/api/js?` + e;
d[q] = f;
a.onerror = () => h = n(Error(p + " could not load."));
a.nonce = m.querySelector("script[nonce]")?.nonce || "";
m.head.append(a)
}));
d[l] ? console.warn(p + " only loads once. Ignoring:", g) : d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n))
})({
key: "",
v: "weekly",
});
</script>
')),
]);
FilamentAsset::register([
Js::make('google-maps')->html(new HtmlString('
<script>
(g => {
var h, a, k, p = "The Google Maps JavaScript API",
c = "google",
l = "importLibrary",
q = "__ib__",
m = document,
b = window;
b = b[c] || (b[c] = {});
var d = b.maps || (b.maps = {}),
r = new Set,
e = new URLSearchParams,
u = () => h || (h = new Promise(async (f, n) => {
await (a = m.createElement("script"));
e.set("libraries", [...r] + "");
for (k in g) e.set(k.replace(/[A-Z]/g, t => "_" + t[0].toLowerCase()), g[k]);
e.set("callback", c + ".maps." + q);
a.src = `https://maps.${c}apis.com/maps/api/js?` + e;
d[q] = f;
a.onerror = () => h = n(Error(p + " could not load."));
a.nonce = m.querySelector("script[nonce]")?.nonce || "";
m.head.append(a)
}));
d[l] ? console.warn(p + " only loads once. Ignoring:", g) : d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n))
})({
key: "",
v: "weekly",
});
</script>
')),
]);
This works, but running php artisan filament:assets produces the following type error Filament\Support\Assets\Asset::getPath(): Return value must be of type string, null returned...
5 replies
FFilament
Created by Arjen on 5/12/2023 in #❓┊help
Prevent beforeOrEqual field from comparing to empty field
See title. Is this possible without resorting to custom rules?
3 replies
FFilament
Created by Arjen on 3/26/2023 in #❓┊help
Programmatically select a tab
Is it possible to programmatically select a tab? I have two tabs but based on a radio field, the first tab may get hidden. If that tab is selected, the other one doesn't automatically get selected so you'll only see the second tab (inactive) without the tab content.
2 replies
FFilament
Created by Arjen on 3/9/2023 in #❓┊help
Error when prefilling from query string in resource with persistTabInQueryString enabled
Hi, I get the following error when persisting tabs in query string enabled when creating a form or uploading files inside the form: https://flareapp.io/share/xPQ3Xol5#F113 The query strings looks like this: ?event_start=2023-03-04&event_end=2023-03-04&tab=tabs-evenement-tab, and the code for filling like this (not sure if it is the correct way to handle it):
class CreatePost extends CreateRecord
{
protected static string $resource = PostResource::class;

protected function afterFill()
{
$validator = Validator::make(
Request::query(),
[
'event_start' => 'required|date:Y-m-d',
'event_end' => 'date:Y-m-d',
]
);
if ($validator->fails()) {
return;
}

$data = $validator->validated();
$this->form->fill([
'has_event' => true,
'event_start' => $data['event_start'] . ' 12:00',
'event_end' => isset($data['event_end']) ? $data['event_end'] . ' 12:00' : null,
]);
}
}
class CreatePost extends CreateRecord
{
protected static string $resource = PostResource::class;

protected function afterFill()
{
$validator = Validator::make(
Request::query(),
[
'event_start' => 'required|date:Y-m-d',
'event_end' => 'date:Y-m-d',
]
);
if ($validator->fails()) {
return;
}

$data = $validator->validated();
$this->form->fill([
'has_event' => true,
'event_start' => $data['event_start'] . ' 12:00',
'event_end' => isset($data['event_end']) ? $data['event_end'] . ' 12:00' : null,
]);
}
}
11 replies
FFilament
Created by Arjen on 3/8/2023 in #❓┊help
Page::$reportValidationErrorUsing dispatchBrowserEvent
Is it possible to do something like this?
Page::$reportValidationErrorUsing = function (ValidationException $exception) {
session()->flash('errors_exception', 'Oeps, het ingevulde formulier bevat één of meerdere problemen.');
session()->flash('errors', $exception->validator->errors());

// Not working because it isn't a static method
Page::dispatchBrowserEvent('scroll-to', [
'query' => "#alert-errors",
'offset' => 120,
]);
};
Page::$reportValidationErrorUsing = function (ValidationException $exception) {
session()->flash('errors_exception', 'Oeps, het ingevulde formulier bevat één of meerdere problemen.');
session()->flash('errors', $exception->validator->errors());

// Not working because it isn't a static method
Page::dispatchBrowserEvent('scroll-to', [
'query' => "#alert-errors",
'offset' => 120,
]);
};
3 replies