datarecall
datarecall
FFilament
Created by datarecall on 4/12/2024 in #❓┊help
Action Keybinds Failing After Use
I created a custom page that runs the following
public function approveAction(): Action
{
return Action::make('Approve')
->keyBindings(['a'])
->color('success')
->action(function(){
$this->media->setCustomProperty('approved', true);
$this->media->save();
Notification::make()
->title('Media has been approved.')
->success()
->send();
$this->getNextMedia();
});
}
private function getNextMedia()
{
$this->index++;
if($this->index >= $this->mediaCollection->count()){
Notification::make()
->title('No non-approved media found.')
->success()
->send();
return redirect()->route('filament.admin.resources.users.index');
}

$this->media = $this->mediaCollection->get($this->index);

$this->url = $this->media->getUrl();
}
public function approveAction(): Action
{
return Action::make('Approve')
->keyBindings(['a'])
->color('success')
->action(function(){
$this->media->setCustomProperty('approved', true);
$this->media->save();
Notification::make()
->title('Media has been approved.')
->success()
->send();
$this->getNextMedia();
});
}
private function getNextMedia()
{
$this->index++;
if($this->index >= $this->mediaCollection->count()){
Notification::make()
->title('No non-approved media found.')
->success()
->send();
return redirect()->route('filament.admin.resources.users.index');
}

$this->media = $this->mediaCollection->get($this->index);

$this->url = $this->media->getUrl();
}
And it IS working however after it loads the next media its almost like the key bind is not bound anymore. I have to hard refresh the page to get the key binds to react. Any ideas on how to persist it?
3 replies
FFilament
Created by datarecall on 3/23/2024 in #❓┊help
->live on custom page Help
I have a custom page
<?php

namespace App\Filament\Resources\FcmNotificationTemplateResource\Pages;

use App\Filament\Resources\FcmNotificationTemplateResource;
use App\Models\FcmNotificationTemplate;
use App\Models\User;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Pages\Page;

class SendTemplateToUser extends Page implements HasForms
{
use InteractsWithForms;

protected static string $resource = FcmNotificationTemplateResource::class;

protected static string $view = 'filament.resources.fcm-notification-template-resource.pages.send-template-to-user';

public function form(Form $form): Form
{
return $form
->schema([
Section::make('Template')
->schema([
Select::make('Template')
->options(FcmNotificationTemplate::all()->pluck('name', 'id'))
->live()
->afterStateUpdated(function (Select $component) {
dd('here');
return $component
->getContainer()
->getComponent('dynamicVariableFields')
->getChildComponentContainer()
->fill();
}),
Select::make('User')
->options(User::all()->pluck('name', 'id'))
->searchable()
]),
Section::make('Variables')
->schema(function (Get $get) {
$templateName = $get('Template');
if(!$templateName) return [];
$template = FcmNotificationTemplate::find($get('Template'));
dd($template);
return [
TextInput::make('title')
->default($template->title),
];
// return collect($template-)->map(function ($variable) {
// return TextInput::make($variable);
// });
})->key('dynamicVariableFields'),
TextInput::make('title')
->required(),
MarkdownEditor::make('content'),
// ...
])
->statePath('data');
}
}
<?php

namespace App\Filament\Resources\FcmNotificationTemplateResource\Pages;

use App\Filament\Resources\FcmNotificationTemplateResource;
use App\Models\FcmNotificationTemplate;
use App\Models\User;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Pages\Page;

class SendTemplateToUser extends Page implements HasForms
{
use InteractsWithForms;

protected static string $resource = FcmNotificationTemplateResource::class;

protected static string $view = 'filament.resources.fcm-notification-template-resource.pages.send-template-to-user';

public function form(Form $form): Form
{
return $form
->schema([
Section::make('Template')
->schema([
Select::make('Template')
->options(FcmNotificationTemplate::all()->pluck('name', 'id'))
->live()
->afterStateUpdated(function (Select $component) {
dd('here');
return $component
->getContainer()
->getComponent('dynamicVariableFields')
->getChildComponentContainer()
->fill();
}),
Select::make('User')
->options(User::all()->pluck('name', 'id'))
->searchable()
]),
Section::make('Variables')
->schema(function (Get $get) {
$templateName = $get('Template');
if(!$templateName) return [];
$template = FcmNotificationTemplate::find($get('Template'));
dd($template);
return [
TextInput::make('title')
->default($template->title),
];
// return collect($template-)->map(function ($variable) {
// return TextInput::make($variable);
// });
})->key('dynamicVariableFields'),
TextInput::make('title')
->required(),
MarkdownEditor::make('content'),
// ...
])
->statePath('data');
}
}
However when the person changes the Template select drodown, nothing is triggering. Do I have to include anything in the template to get this to work?
4 replies
FFilament
Created by datarecall on 3/20/2024 in #❓┊help
Multiple Text Inputs From Relationship / Saving To Pivot
Ok modifying this question to use a hasMany/pivot relationship. I have a model that has a list of questions and belongs to a career
class CareerQuestion extends Model
{
public function career()
{
return $this->belongsTo(Career::class);
}

public function applications()
{
return $this->belongsToMany(CareerApplication::class, 'applications_questions')
->withPivot('answer')
->withTimestamps();
}
}
class CareerQuestion extends Model
{
public function career()
{
return $this->belongsTo(Career::class);
}

public function applications()
{
return $this->belongsToMany(CareerApplication::class, 'applications_questions')
->withPivot('answer')
->withTimestamps();
}
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CareerApplication extends Model
{
public function career()
{
return $this->belongsTo(Career::class);
}

public function questions()
{
return $this->belongsToMany(CareerQuestion::class, 'applications_questions')
->withPivot('answer')
->withTimestamps();
}
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CareerApplication extends Model
{
public function career()
{
return $this->belongsTo(Career::class);
}

public function questions()
{
return $this->belongsToMany(CareerQuestion::class, 'applications_questions')
->withPivot('answer')
->withTimestamps();
}
}
Then I am making a form that will loop through all the questions and give a text input so they can store their answers on the pivot table, I have tried a few different way's however I do not think i am on the right track.
Repeater::make('questions')
->relationship('questions')
->schema([
TextInput::make('answer')
->required(),
])
->itemLabel(fn (array $state): ?string => $state['question'] ?? 'SHOULD NEVER REACH HERE'),
Repeater::make('questions')
->relationship('questions')
->schema([
TextInput::make('answer')
->required(),
])
->itemLabel(fn (array $state): ?string => $state['question'] ?? 'SHOULD NEVER REACH HERE'),
When loading the form the SHOULD NEVER REACH HERE is showing and only 1 evern though there is 4 questions. I am guessing I have the repeater relationship setup wrong ?
3 replies
FFilament
Created by datarecall on 3/4/2024 in #❓┊help
Custom Page Table Actions Help - still broken
I have a custom page the table is showing fine however when I click on the action nothing is happening, it should be dumping the record. The end goal of this action is to run this query inside the action itself
UserTranslation::query()
->where('user_id', $record->user_id)
->update(['is_paid' => true]);
UserTranslation::query()
->where('user_id', $record->user_id)
->update(['is_paid' => true]);
However clicking on the action displays/does nothing itself, I tested the action on an actual resource and it works.
<?php

namespace Kenepa\TranslationManager\Pages;

use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\Page;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use Kenepa\TranslationManager\Models\UserTranslation;
use Kenepa\TranslationManager\Resources\LanguageLineResource;
use Kenepa\TranslationManager\Traits\CanRegisterPanelNavigation;

class TranslationBilling extends Page implements HasForms, HasTable
{
use CanRegisterPanelNavigation;
use InteractsWithTable;
use InteractsWithForms;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
// protected static ?string $navigationGroup = 'MyNavigationGroup';

protected static string $view = 'translation-manager::translation-billing';
protected static string $resource = LanguageLineResource::class;

public static function shouldRegisterNavigation(array $parameters = []): bool
{
return static::shouldRegisterOnPanel() ? config('translation-manager.quick_translate_navigation_registration') : false;
}
public static function getNavigationGroup(): ?string
{
return config('translation-manager.navigation_group');
}

public static function getNavigationIcon(): ?string
{
return 'heroicon-o-currency-dollar';
}
public function mount(): void
{
abort_unless(static::shouldRegisterOnPanel(), 403);
}
public function getTableRecordKey($record): string
{
return (string) $record->getKeyName();
}

public function table(Table $table): Table
{
return $table
->query(
UserTranslation::query()
->select('user_id', DB::raw('SUM(word_count) as total_word_count'))
->where('is_paid', false)
->groupBy('user_id')
->orderBy('total_word_count', 'desc')
)
->columns([
TextColumn::make('user.name')
->searchable(),
TextColumn::make('total_word_count')
->sortable(),
])
->filters([
// ...
])
->actions([
Action::make('mark_paid')
->label('Mark Paid')
->icon('heroicon-o-currency-dollar')
->color('success')
->before(function ($record) {
dd('hello');
})
->action(function ($record) {
dd($record);
})
->after(function(){
Notification::make()
->duration(3000)
->success()
->title('User Paid')
->body('User has been marked as paid.')
->send();
})
])
->bulkActions([
// ...
]);
}
}
<?php

namespace Kenepa\TranslationManager\Pages;

use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\Page;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use Kenepa\TranslationManager\Models\UserTranslation;
use Kenepa\TranslationManager\Resources\LanguageLineResource;
use Kenepa\TranslationManager\Traits\CanRegisterPanelNavigation;

class TranslationBilling extends Page implements HasForms, HasTable
{
use CanRegisterPanelNavigation;
use InteractsWithTable;
use InteractsWithForms;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
// protected static ?string $navigationGroup = 'MyNavigationGroup';

protected static string $view = 'translation-manager::translation-billing';
protected static string $resource = LanguageLineResource::class;

public static function shouldRegisterNavigation(array $parameters = []): bool
{
return static::shouldRegisterOnPanel() ? config('translation-manager.quick_translate_navigation_registration') : false;
}
public static function getNavigationGroup(): ?string
{
return config('translation-manager.navigation_group');
}

public static function getNavigationIcon(): ?string
{
return 'heroicon-o-currency-dollar';
}
public function mount(): void
{
abort_unless(static::shouldRegisterOnPanel(), 403);
}
public function getTableRecordKey($record): string
{
return (string) $record->getKeyName();
}

public function table(Table $table): Table
{
return $table
->query(
UserTranslation::query()
->select('user_id', DB::raw('SUM(word_count) as total_word_count'))
->where('is_paid', false)
->groupBy('user_id')
->orderBy('total_word_count', 'desc')
)
->columns([
TextColumn::make('user.name')
->searchable(),
TextColumn::make('total_word_count')
->sortable(),
])
->filters([
// ...
])
->actions([
Action::make('mark_paid')
->label('Mark Paid')
->icon('heroicon-o-currency-dollar')
->color('success')
->before(function ($record) {
dd('hello');
})
->action(function ($record) {
dd($record);
})
->after(function(){
Notification::make()
->duration(3000)
->success()
->title('User Paid')
->body('User has been marked as paid.')
->send();
})
])
->bulkActions([
// ...
]);
}
}
23 replies
FFilament
Created by datarecall on 2/26/2024 in #❓┊help
Custom Icon Column
No description
10 replies
FFilament
Created by datarecall on 1/7/2024 in #❓┊help
View Page (infolist) Add Form
No description
1 replies
FFilament
Created by datarecall on 12/27/2023 in #❓┊help
Markdown editor to use spatie media library
Is there a way I can get the markdown editor to utilize spatie's media library? We host using vapor so we can not upload to the app directly.
2 replies
FFilament
Created by datarecall on 9/26/2023 in #❓┊help
Custom Page
I want to create a custom page where a user can execute a specific sql query, I created the custom page and linked it so from user resource they can get to it from head actions. The user is :
http://localhost/admin/users/3/votables
http://localhost/admin/users/3/votables
However I cant find any documentation on how to execute a specific sql query on my custom page or show the results using table builder.
<?php

namespace App\Filament\Resources\UserResource\Pages;

use App\Filament\Resources\UserResource;
use Filament\Resources\Pages\Page;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;

class ViewVotables extends Page
{
protected static string $resource = UserResource::class;

protected static string $view = 'filament.resources.user-resource.pages.view-votables';

public function table(Table $table): Table
{
dd('here');
}
}
<?php

namespace App\Filament\Resources\UserResource\Pages;

use App\Filament\Resources\UserResource;
use Filament\Resources\Pages\Page;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;

class ViewVotables extends Page
{
protected static string $resource = UserResource::class;

protected static string $view = 'filament.resources.user-resource.pages.view-votables';

public function table(Table $table): Table
{
dd('here');
}
}
26 replies
FFilament
Created by datarecall on 9/26/2023 in #❓┊help
Sort by Attribute
I have an attribute called age that gets the age of the user calculated by their DOB, how can I create a sortable on this column.
7 replies
FFilament
Created by datarecall on 9/13/2023 in #❓┊help
Relations Table Edit To Redirect?
I find myself when doing having relationships to be duplicating code for the table and the form inside the relation manager. Is there a way to have it in one place, the table for the relation manager should be the table for the resource and the Edit button instead of a modal should just redirect to the edit resource instead?
4 replies
FFilament
Created by datarecall on 9/13/2023 in #❓┊help
Card Deprecated ?
What is the proper way to add a card to a form now?
6 replies
FFilament
Created by datarecall on 9/6/2023 in #❓┊help
Filter Resource List
I have an activity log and I want to create a notification log so I would need to add a scope to the intial query that will add
->where('log_name','notifications')
->where('log_name','notifications')
then this data will be fed into the table builder, how do I go about doing that?
3 replies
FFilament
Created by datarecall on 8/22/2023 in #❓┊help
Upgrade to v3 + Vapor Error
3 replies
FFilament
Created by datarecall on 8/19/2023 in #❓┊help
Personal Plugin v3 Upgrade not showing up
I have a personal blog plugin for filament, here is my service provider. From the documentation it looks like we can still use spatie package tools here is my service provider
<?php

namespace Illusive\Blog;

//use Filament\PluginServiceProvider;
use Illusive\Blog\Commands\CreatePostLowestCategoryCommand;
use Illusive\Blog\Commands\InstallCommand;
use Illusive\Blog\Middleware\IncrementPostViewsMiddleware;
use Illusive\Blog\Resources\AuthorResource;
use Illusive\Blog\Resources\CategoryResource;
use Illusive\Blog\Resources\PostResource;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

class BlogServiceProvider extends PackageServiceProvider
{
protected array $resources = [
AuthorResource::class,
CategoryResource::class,
PostResource::class,
];

public function configurePackage(Package $package): void
{
$package
->name('filament-blog')
->hasConfigFile()
->hasTranslations()
->hasCommand(InstallCommand::class)
->hasCommand(CreatePostLowestCategoryCommand::class)
->hasRoute('web')
->hasMigration('create_filament_blog_tables')
->hasMigration('update_blog_tables_2023-08-2');

$this->publishes([__DIR__.'/../resources/js/Pages' => resource_path('js/Pages')], 'vue-blog-pages');
$this->publishes([__DIR__.'/../resources/js/BlogPagination.vue' => resource_path('js/Components/BlogPagination.vue')], 'vue-blog-pages');
$this->publishes([__DIR__.'/../resources/js/BlogContentContainer.vue' => resource_path('js/Components/BlogContentContainer.vue')], 'vue-blog-pages');

$this->app['router']->aliasMiddleware('increment.views', IncrementPostViewsMiddleware::class);
}
}
<?php

namespace Illusive\Blog;

//use Filament\PluginServiceProvider;
use Illusive\Blog\Commands\CreatePostLowestCategoryCommand;
use Illusive\Blog\Commands\InstallCommand;
use Illusive\Blog\Middleware\IncrementPostViewsMiddleware;
use Illusive\Blog\Resources\AuthorResource;
use Illusive\Blog\Resources\CategoryResource;
use Illusive\Blog\Resources\PostResource;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

class BlogServiceProvider extends PackageServiceProvider
{
protected array $resources = [
AuthorResource::class,
CategoryResource::class,
PostResource::class,
];

public function configurePackage(Package $package): void
{
$package
->name('filament-blog')
->hasConfigFile()
->hasTranslations()
->hasCommand(InstallCommand::class)
->hasCommand(CreatePostLowestCategoryCommand::class)
->hasRoute('web')
->hasMigration('create_filament_blog_tables')
->hasMigration('update_blog_tables_2023-08-2');

$this->publishes([__DIR__.'/../resources/js/Pages' => resource_path('js/Pages')], 'vue-blog-pages');
$this->publishes([__DIR__.'/../resources/js/BlogPagination.vue' => resource_path('js/Components/BlogPagination.vue')], 'vue-blog-pages');
$this->publishes([__DIR__.'/../resources/js/BlogContentContainer.vue' => resource_path('js/Components/BlogContentContainer.vue')], 'vue-blog-pages');

$this->app['router']->aliasMiddleware('increment.views', IncrementPostViewsMiddleware::class);
}
}
From what I can see its not registering the routes so may not be running the service provider ?
60 replies
FFilament
Created by datarecall on 8/19/2023 in #❓┊help
v3 upgrade
8 replies
FFilament
Created by datarecall on 8/2/2023 in #❓┊help
Help With Form URLS
I have a blog post that uses markdown syntax and I created the ability (spatie) to add attachments to the post. Now I need a way to list them so the user can copy the url into the blog post. This is whave I have so far:
Forms\Components\Placeholder::make('attachments')
->label(__('filament-blog::filament-blog.attachment_list'))
->content(function (?Post $record): string {
if (!$record) {
return 'None';
}

$attachments = $record->getMedia('attachments');

if ($attachments->isEmpty()) {
return 'None';
}

// Build an array of URLs for each media
$attachmentUrls = $attachments->map(function (Media $media) {
return sprintf('<li>%s</li>', $media->getFullUrl());
});


// You can now access the array of URLs as needed
// For example, join them with line breaks:
return sprintf('<ul>%s</ul>', $attachmentUrls->join("\n"));
}),
Forms\Components\Placeholder::make('attachments')
->label(__('filament-blog::filament-blog.attachment_list'))
->content(function (?Post $record): string {
if (!$record) {
return 'None';
}

$attachments = $record->getMedia('attachments');

if ($attachments->isEmpty()) {
return 'None';
}

// Build an array of URLs for each media
$attachmentUrls = $attachments->map(function (Media $media) {
return sprintf('<li>%s</li>', $media->getFullUrl());
});


// You can now access the array of URLs as needed
// For example, join them with line breaks:
return sprintf('<ul>%s</ul>', $attachmentUrls->join("\n"));
}),
this will output the url fine but its showing the html so I am gussing this is escaped. I was wondering if it would be possible to create a table here or display the images and then utilize a click to copy url.
8 replies
FFilament
Created by datarecall on 8/1/2023 in #❓┊help
Can a Relation manager use get actions?
I have a Resource for category and a relation for posts in that category, I want to create a generate button sort of like create button on the top right hand side. I have this in my PostRelationsManager.php
protected function getActions(): array
{
$actions[] = CreateAction::class::make();
$actions[] = Action::make('Generate')
->color('danger')
->requiresConfirmation()
->icon('heroicon-o-document-search')
->action('generatePost');

return $actions;
}
protected function getActions(): array
{
$actions[] = CreateAction::class::make();
$actions[] = Action::make('Generate')
->color('danger')
->requiresConfirmation()
->icon('heroicon-o-document-search')
->action('generatePost');

return $actions;
}
15 replies