Fossil
Fossil
FFilament
Created by Fossil on 5/18/2024 in #❓┊help
2FA Middleware
I use Filament as the admin panel for my app. Whenever I login to my app, I get a 2FA screen after clicking login and the rest of the apps routes are not working before 2FA is completed. Now when I don't enter my 2FA, and try to open my Filament route instead I get the actual dashboard and everything is working. I can delete users etc. IE: Security hole. How can I apply my 2FA Middleware? Whenever I add \App\Http\Middleware\Google2FAMiddleware::class to the middleware() or authMiddleware() methods on my public function panel(Panel $panel): Panel in AdminPanelProvider.php it doesn't change anything.
22 replies
FFilament
Created by Fossil on 4/13/2024 in #❓┊help
Value not updated when clicking save
I have a column called videos_id in my table. And a videos table where that ID is the primary key id and a column called title. In this dropdown on the Filament Edit page I want to show the title and not the ID. So I am doing this:
Select::make('videos_id')
->getSearchResultsUsing(fn (string $search): array => Video::where('title', 'like', "%{$search}%")->limit(50)->pluck('title', 'id')->toArray())
->getOptionLabelUsing(
function ($value) {
$video = Video::find($value);
$title = $video ? $video->title : null;
$started = $video ? $video->started : null;

$year = null;
if ($started !== null) {
$carbonDate = Carbon::createFromDate($started);
$year = $carbonDate->format('Y');
}

return $title !== null ? $title.' ('.$year.')' : null;
}
)
->searchable()
->live()
->default(0)
->label('Video ID'),
Select::make('videos_id')
->getSearchResultsUsing(fn (string $search): array => Video::where('title', 'like', "%{$search}%")->limit(50)->pluck('title', 'id')->toArray())
->getOptionLabelUsing(
function ($value) {
$video = Video::find($value);
$title = $video ? $video->title : null;
$started = $video ? $video->started : null;

$year = null;
if ($started !== null) {
$carbonDate = Carbon::createFromDate($started);
$year = $carbonDate->format('Y');
}

return $title !== null ? $title.' ('.$year.')' : null;
}
)
->searchable()
->live()
->default(0)
->label('Video ID'),
Which works fine. But when I change the value and click Save. The old ID is still present on the row. Devtools show a POST request to /livewire/update with JSON data which does contain the NEW id. So I am puzzled why this happens.
{
"data": {
"data": [
{
"id": 10,
"videos_id": "41",
{
"data": {
"data": [
{
"id": 10,
"videos_id": "41",
Removed all the other data from the JSON to make it readable.
7 replies
FFilament
Created by Fossil on 1/6/2024 in #❓┊help
On/off toggle based on relationship? (Spatie/Laravel Permission)
I have this toggle to on/off certain permissions on the Edit User resource. How do I make that work with permissions stored in another table using Laravel Permission by Spatie?
Toggle::make('testPermission')->label('Test');
Toggle::make('testPermission')->label('Test');
Basically a name in the permissions table could be 'view this' with id = 9 for example. I need t check if it exists for this userID and turn the toggle on/off based on that. If exists and I turn off the toggle it should delete and vice versa.
4 replies
FFilament
Created by Fossil on 1/6/2024 in #❓┊help
Custom delete logic?
My app requires some files on disk to be delete when a model is deleted. I have a function in the model that handles this plus the row deletion in DB itself. Any way I could make the delete and bulk delete functions in Filament call this code instead of just removing the record from the DB?
3 replies
FFilament
Created by Fossil on 12/21/2023 in #❓┊help
Call function on save?
Need to call a syncRoles() function inside User model after editing a user. Preferably only when roles_id changed but could call it always on save. How would I do so?
3 replies
FFilament
Created by Fossil on 12/7/2023 in #❓┊help
Header action modal to search API, how to show results properly?
So I have a header action which opens a modal. The modal houses a form field which allows you to search an external API. I process the results in the ->action(function (array $data) {} method. Now I want to loop over the results and build a nice HTML table or something so a user can pick a result. However I when I do var_dump($data); I get nothing. When I do dd($data) I see my data in a black dd() screen of course so it's there. Any way of presenting this data to this or another modal and fire some PHP code when a user clicks a result?
\Filament\Actions\Action::make('searchapi')
->label('Search')
->icon('heroicon-o-arrow-path')
->color('info')
->form([
TextInput::make('title')->required(),
])
->action(function (array $data) {
// Call external API here with $data['title'] and put result in $results
var_dump($results); // Nothing. Just shows loading spinner on TextInput Submit button
}),
\Filament\Actions\Action::make('searchapi')
->label('Search')
->icon('heroicon-o-arrow-path')
->color('info')
->form([
TextInput::make('title')->required(),
])
->action(function (array $data) {
// Call external API here with $data['title'] and put result in $results
var_dump($results); // Nothing. Just shows loading spinner on TextInput Submit button
}),
28 replies