damms005
damms005
FFilament
Created by damms005 on 8/2/2024 in #❓┊help
Any way to toggle first in client-side?
Toggle column is absolutely awesome for what it does. However, because it is not entangled, it does not have a good UX when working with slow internet. How can I improve this please? (e.g. let the toggle happen client side while server roundtrip happen background)
2 replies
FFilament
Created by damms005 on 2/2/2024 in #❓┊help
How to prevent dashboard widget filter persistence across page refresh
When filtering dashboard widgets, the filter is persisted across page refresh. How do I disable this so that the filtering refreshes on page refresh?
2 replies
FFilament
Created by damms005 on 1/30/2024 in #❓┊help
How to fix login redirect loop
No description
5 replies
FFilament
Created by damms005 on 1/25/2024 in #❓┊help
How to prevent accidental data leak
Filament uses model policies to prevent unauthorized access. I have had situations where I forgot to add model policies, especially for existing models and I add the resource to Filament. Maybe the solution is a Laravel thing rather than Filament, but how can I prevent such error? More specifically: How can I make Filament blow up (throw Exception or something) when a resource is accessed and the underlying model does not have any policy class?
6 replies
FFilament
Created by damms005 on 11/25/2023 in #❓┊help
How to create custom filament page that is accessible to guests?
I created a new page using the create page command but when I access it browser redirects to login page. How can I prevent this and get the page rendered so guests can access without need to login?
8 replies
FFilament
Created by damms005 on 10/26/2023 in #❓┊help
How do I dynamically create table columns in my admin panel?
My database table has name and value columns. I currently use TextColumn for both, like this:
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('value'),
])
...
...
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('value'),
])
...
...
How do I dynamically set the column for value based on the value of name?
12 replies
FFilament
Created by damms005 on 7/21/2023 in #❓┊help
How do I assign middleware to a Page or Resource?
I do come across this concept of Filament middlewares many times. Most recently, it is mentioned in the beta docs like this: Property signature changes Resource classes and all page classes, including resource pages, custom pages, settings pages, and dashboard pages: $middlewares is now $routeMiddleware This gives the impression that middlewares can be assigned directly to pages or resources. However, this is not documented anywhere in Filament how to achieve this. Can someone please point me to the relevant parts of the docs, please?
2 replies
FFilament
Created by damms005 on 7/9/2023 in #❓┊help
How to visit Filament dashboard from the central domain after integrating stancl/tenancy
I have setup stancl/tenancy according to the Filament docs and it works well together. However, I am now unable to visit Filament from the central domain, with error:
Hostname schoolserver.test does not include a subdomain.
Hostname schoolserver.test does not include a subdomain.
I understand the error because I set up stancl/tenancy to to identify tenants by subdomain (which, like I said, works well). It seems that including InitializeTenancyByDomain::class in Filament's middleware.base config entry makes the whole of Filament to be a tenant thing. Please, what are my options for allowing Cetral domain admin to visit Filament while tenants can still visit Filament?
6 replies
FFilament
Created by damms005 on 4/15/2023 in #❓┊help
What options do I have to render html in notifications?
I'm taking about purely backend, not frontend js notifications. Per the usual Filament's Notification::make(...)->body(...) If it's not supported yet, any plan to support it or PR accepted? cc @Dan Harrin
3 replies
FFilament
Created by damms005 on 4/15/2023 in #❓┊help
How to get uploaded file in page action
In my List page, I have a page action with a form that contains a FileUpload::make('test-file'). In the ->action(fn (array $data)...) I need to get the uploaded file. According to the docs, I should do $data['test-file'] but that only contained a string (I think the internal livewire temp value for the file). How do I get the uploaded file in the $data ? Currently, I do something like:
$filePath = Storage::disk('public')->path(array_values($this->mountedActionData['test-file'])[0]);
$filePath = Storage::disk('public')->path(array_values($this->mountedActionData['test-file'])[0]);
Is there a better way?
4 replies
FFilament
Created by damms005 on 3/29/2023 in #❓┊help
Resource policy issue
From the docs, edit route should only check the update() policy method. Now, I have this weird issue of it checking the viewAny() method. What may I be doing wrong? StaffPolicy.php
<?php

namespace App\Policies;

use App\Staff;
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class StaffPolicy
{
use HandlesAuthorization;

public function viewAny(User $user)
{
dd('1');
return $user->can('edit staff permissions');
}

public function create(User $user)
{
dd('3');
return false;
}

public function update(User $user, Staff $staff)
{
dd('4');
if ($user->id === $staff->user_id) {
return true;
}

return $user->can('edit staff permissions');
}
}
<?php

namespace App\Policies;

use App\Staff;
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class StaffPolicy
{
use HandlesAuthorization;

public function viewAny(User $user)
{
dd('1');
return $user->can('edit staff permissions');
}

public function create(User $user)
{
dd('3');
return false;
}

public function update(User $user, Staff $staff)
{
dd('4');
if ($user->id === $staff->user_id) {
return true;
}

return $user->can('edit staff permissions');
}
}
StaffTest.php
<?php

use App\Filament\Resources\StaffResource;
use Symfony\Component\HttpKernel\Exception\HttpException;
use App\Filament\Resources\StaffResource\RelationManagers\UserModelRelationManager;
use Spatie\Permission\Models\Permission;

beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'PermissionSeeder']);
$user = addStaff();
$this->user = $user;
$this->actingAs($this->user);
});


it('allows user to view self\'s staff resource', function () {
$this->get(StaffResource::getUrl('edit', [
'record' => $this->user->staffModel
]))
->assertSuccessful();
});
<?php

use App\Filament\Resources\StaffResource;
use Symfony\Component\HttpKernel\Exception\HttpException;
use App\Filament\Resources\StaffResource\RelationManagers\UserModelRelationManager;
use Spatie\Permission\Models\Permission;

beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'PermissionSeeder']);
$user = addStaff();
$this->user = $user;
$this->actingAs($this->user);
});


it('allows user to view self\'s staff resource', function () {
$this->get(StaffResource::getUrl('edit', [
'record' => $this->user->staffModel
]))
->assertSuccessful();
});
Console output:
❯ ./vendor/bin/sail pest tests/Feature/RolesAndPermissions/StaffTest.php --filter "allows user to view self's staff resource"
"1" // app/Policies/StaffPolicy.php:21 <- the dd() code
❯ ./vendor/bin/sail pest tests/Feature/RolesAndPermissions/StaffTest.php --filter "allows user to view self's staff resource"
"1" // app/Policies/StaffPolicy.php:21 <- the dd() code
8 replies
FFilament
Created by damms005 on 3/23/2023 in #❓┊help
How can I get changes to resource form?
I want to log changes to a pivot table. Creating a pivot Model is not an option, so I need to hook to the before-save event, so I can get the old/new values to log. How can I achieve this please?
21 replies
FFilament
Created by damms005 on 3/17/2023 in #❓┊help
How do I get the "create" routes for simple-modal-resources in testing?
While this is easy for normal pages (see https://filamentphp.com/docs/2.x/admin/testing#routing--render-1), I am unable to figure out how to test "create" of #Simple (modal) resources - https://filamentphp.com/docs/2.x/admin/resources/getting-started#simple-modal-resources
3 replies
FFilament
Created by damms005 on 3/9/2023 in #❓┊help
How do I add "forgot password" link to login page?
How do I add "forgot password" link to login page?
23 replies