LancelotGamer
LancelotGamer
FFilament
Created by LancelotGamer on 9/11/2024 in #❓┊help
Reorderable button does not update automatically {hide/show} when the condition argument changes
I have this code in my resource class
public static function table(Table $table): Table
{
return $table
->reorderable('order_index', function ($livewire) {
return $livewire->activeTab !== 'all';
})
->columns([
...
])
->filters([
//
])
->actions([
...
])
->bulkActions([
//
]);
}
public static function table(Table $table): Table
{
return $table
->reorderable('order_index', function ($livewire) {
return $livewire->activeTab !== 'all';
})
->columns([
...
])
->filters([
//
])
->actions([
...
])
->bulkActions([
//
]);
}
And I have this code in my ListRecords class
public function getTabs(): array
{
return [
'all' => Tab::make('All Violations'),
'user' => Tab::make('User Violations')
->modifyQueryUsing(fn($query) => $query->where('entity', 'user')),
'status' => Tab::make('Status Violations')
->modifyQueryUsing(fn($query) => $query->where('entity', 'status')),
];
}
public function getTabs(): array
{
return [
'all' => Tab::make('All Violations'),
'user' => Tab::make('User Violations')
->modifyQueryUsing(fn($query) => $query->where('entity', 'user')),
'status' => Tab::make('Status Violations')
->modifyQueryUsing(fn($query) => $query->where('entity', 'status')),
];
}
When I change the tab, I want the reorder button to appear only if the tab is not equal to all. The reorder button is always hidden.
2 replies
FFilament
Created by LancelotGamer on 1/3/2024 in #❓┊help
Issue when adding a sticky button to the panel using render hooks
No description
2 replies
FFilament
Created by LancelotGamer on 12/23/2023 in #❓┊help
Pie widget bug
I have a widget to display some info But there are numbers that are not suppose to show
return [
'datasets' => [
[
'label' => 'Ticket Chart',
'data' => [
$archivedTickets,
$canceledTickets,
$closedTickets,
$escalatedToHighTechnicalSupport,
$escalatedToExternalTechnicalSupport,
$openedTickets,
],
'backgroundColor' => [
'rgb(255, 205, 86)',
'rgb(255, 99, 132)',
'rgb(75, 192, 192)',
'rgb(153, 102, 255)',
'rgb(255, 159, 64)',
'rgb(54, 162, 235)',
],
],
],
'labels' => [
'Archived Tickets',
'Canceled Tickets',
'Closed Tickets',
'Escalated To SL2',
'Escalated To SL3',
'Opened Tickets',
],
];
return [
'datasets' => [
[
'label' => 'Ticket Chart',
'data' => [
$archivedTickets,
$canceledTickets,
$closedTickets,
$escalatedToHighTechnicalSupport,
$escalatedToExternalTechnicalSupport,
$openedTickets,
],
'backgroundColor' => [
'rgb(255, 205, 86)',
'rgb(255, 99, 132)',
'rgb(75, 192, 192)',
'rgb(153, 102, 255)',
'rgb(255, 159, 64)',
'rgb(54, 162, 235)',
],
],
],
'labels' => [
'Archived Tickets',
'Canceled Tickets',
'Closed Tickets',
'Escalated To SL2',
'Escalated To SL3',
'Opened Tickets',
],
];
12 replies
FFilament
Created by LancelotGamer on 12/20/2023 in #❓┊help
Download action button behaves weirdly
No description
4 replies
FFilament
Created by LancelotGamer on 11/1/2023 in #❓┊help
How can I throw an exception and send a notification in handleRecordCreation() method
I am trying to send an email when I create a record If the email was not send an exception is thrown I am catching the exception then I am sending a notification But I am getting this error: App\Filament\Resources\TicketResource\Pages\CreateTicket::handleRecordCreation(): Return value must be of type Illuminate\Database\Eloquent\Model, none returned
protected function handleRecordCreation(array $data): Model
{
try {
//..
Mail::to($created->customer)->send(new TicketCreated($title));
return $created;
} catch (Exception $e) {
if (App::environment('local')) {
Notification::make()
->title($e->getMessage())
->danger()
->send();
} else {
Notification::make()
->title('Something went wrong')
->danger()
->send();
}
}
}
protected function handleRecordCreation(array $data): Model
{
try {
//..
Mail::to($created->customer)->send(new TicketCreated($title));
return $created;
} catch (Exception $e) {
if (App::environment('local')) {
Notification::make()
->title($e->getMessage())
->danger()
->send();
} else {
Notification::make()
->title('Something went wrong')
->danger()
->send();
}
}
}
How can I handle this?
8 replies
FFilament
Created by LancelotGamer on 10/23/2023 in #❓┊help
How can I hide/disable the back button in the wizard layout?
Is it possible to hide/disable the back button in the Wizard layout? I don't want the user to go to the previous step https://filamentphp.com/docs/3.x/forms/layout/wizard Another question: When I added a custom submit button to the wizard layout, it dose not show the loading animation.
2 replies
FFilament
Created by LancelotGamer on 10/18/2023 in #❓┊help
How can I get the state of the file upload and save the uploaded files
I have a form action to upload multiple files
//...
FileUpload::make('attachments')
->multiple()
->columnSpanFull(),
//...
//...
FileUpload::make('attachments')
->multiple()
->columnSpanFull(),
//...
When I upload more than 2 files, I am getting only the last uploaded file name
->action(function (array $data, Ticket $record) {
dd($data['attachments']);
->action(function (array $data, Ticket $record) {
dd($data['attachments']);
dd output: array:1 [▼ // app\Filament\Resources\TicketResource\Pages\EditTicket.php:423 0 => "EUAPX1blrjo62ngqh7ZkUw0BzlA8vB-metac3NsYWNjZXNzbG9nX3ZpYnJhZm9uZS5jb18xMF8xN18yMDIzLmd6-.gz" ]
2 replies
FFilament
Created by LancelotGamer on 10/11/2023 in #❓┊help
Issue with multi-select and $data array
The $data array is null even if I add an item / items in the multi select
Actions\Action::make('assign_ticket')
->form([
Select::make('users')
->label('Technical Support User')
->multiple()
->relationship('technicalSupport', 'email', function ($record, Builder $query) {
$query
->where('department_id', $record->department_id)
->where('level_id', '=', 2);
})
->required(),
])
->action(function (array $data, Ticket $record): void {
dd($data);
}),
Actions\Action::make('assign_ticket')
->form([
Select::make('users')
->label('Technical Support User')
->multiple()
->relationship('technicalSupport', 'email', function ($record, Builder $query) {
$query
->where('department_id', $record->department_id)
->where('level_id', '=', 2);
})
->required(),
])
->action(function (array $data, Ticket $record): void {
dd($data);
}),
3 replies
FFilament
Created by LancelotGamer on 10/9/2023 in #❓┊help
Select Menu issue while in dark mode
No description
27 replies
FFilament
Created by LancelotGamer on 10/8/2023 in #❓┊help
What is the best way to separate the create form and the edit form in a resource
public static function form(Form $form): Form
{
return $form
->schema([
Section::make()
->visible(fn (Page $livewire) => $livewire instanceof CreateModel)
->schema([
// ...
]),
Section::make()
->visible(fn (Page $livewire) => $livewire instanceof EditModel)
->schema([
// ...
])
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Section::make()
->visible(fn (Page $livewire) => $livewire instanceof CreateModel)
->schema([
// ...
]),
Section::make()
->visible(fn (Page $livewire) => $livewire instanceof EditModel)
->schema([
// ...
])
]);
}
Is this a good solution ?
4 replies
FFilament
Created by LancelotGamer on 10/7/2023 in #❓┊help
package issue (jeffgreco13/filament-breezy)
After running composer require jeffgreco13/filament-breezy An error appeared BadMethodCallException Method Filament\Panel::getDomains does not exist. at vendor\filament\support\src\Concerns\Macroable.php:72 68▕ { 69▕ $macro = static::getMacro($method); 70▕ 71▕ if ($macro === null) { ➜ 72▕ throw new BadMethodCallException(sprintf( 73▕ 'Method %s::%s does not exist.', 74▕ static::class, 75▕ $method, 76▕ )); i Bad Method Call: Did you mean Filament\Panel::getDomain() ? 1 vendor\jeffgreco13\filament-breezy\routes\web.php:10 Filament\Support\Components\Component::__call("getDomains", []) 2 vendor\laravel\framework\src\Illuminate\Routing\Router.php:502 Illuminate\Support\ServiceProvider::{closure}(Object(Illuminate\Routing\Router)) Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1 Using filament v3
3 replies
FFilament
Created by LancelotGamer on 9/14/2023 in #❓┊help
'No records found' message inside a repeater
Is it possible to to display a message when there is no records inside a repeater?
3 replies
FFilament
Created by LancelotGamer on 9/13/2023 in #❓┊help
Is this the correct way to add a transaction when updating a model
protected function handleRecordUpdate(Model $record, array $data): Model
{
DB::transaction(function () use ($record, $data) {
$record->update($data);
});
return $record;
}
protected function handleRecordUpdate(Model $record, array $data): Model
{
DB::transaction(function () use ($record, $data) {
$record->update($data);
});
return $record;
}
I have an observer with {public $afterCommit = true;} property. Will this work ?
5 replies
FFilament
Created by LancelotGamer on 9/11/2023 in #❓┊help
How can I populate repeater's relation in an action from
Tables\Actions\Action::make('show_reports')
->record(fn ($record) => $record)
->form([
Forms\Components\Repeater::make('reports')
->relationship('reports')
->disableItemCreation()
->disableItemDeletion()
->disableItemMovement()
->schema([
Forms\Components\TextInput::make('violation_id')
->disabled()
->disableLabel(),
Forms\Components\TextInput::make('admin_comment')
->disabled()
->disableLabel(),
])
])
->action(function () {
}),
Tables\Actions\Action::make('show_reports')
->record(fn ($record) => $record)
->form([
Forms\Components\Repeater::make('reports')
->relationship('reports')
->disableItemCreation()
->disableItemDeletion()
->disableItemMovement()
->schema([
Forms\Components\TextInput::make('violation_id')
->disabled()
->disableLabel(),
Forms\Components\TextInput::make('admin_comment')
->disabled()
->disableLabel(),
])
])
->action(function () {
}),
The repeater fields are empty I tried adding ->record(fn ($record) => $record) but did not work
Forms\Components\Repeater::make('reports')
->relationship('reports')
->disableItemCreation()
->disableItemDeletion()
->disableItemMovement()
->schema([
Forms\Components\TextInput::make('violation_id')
->disabled()
->disableLabel(),
Forms\Components\TextInput::make('admin_comment')
->disabled()
->disableLabel(),
])
Forms\Components\Repeater::make('reports')
->relationship('reports')
->disableItemCreation()
->disableItemDeletion()
->disableItemMovement()
->schema([
Forms\Components\TextInput::make('violation_id')
->disabled()
->disableLabel(),
Forms\Components\TextInput::make('admin_comment')
->disabled()
->disableLabel(),
])
This code works fine when I place it in the edit page form builder
4 replies
FFilament
Created by LancelotGamer on 9/1/2023 in #❓┊help
Reactive Column
Is it possible to create a reactive SelectColumn
6 replies
FFilament
Created by LancelotGamer on 8/26/2023 in #❓┊help
FileUpload with url
I am uploading my images using a service and it is working fine, But 😦 How can the FileUpload field show a file via url
Forms\Components\FileUpload::make('image_upload')
->afterStateUpdated(
function (Closure $set, Closure $get, TemporaryUploadedFile $state, HandleImagesService $handleImagesService) {
$set(
'image_id',
$handleImagesService->handleImage(
null,
$state,
ModelsNamesWithImages::STATUS_IMAGE,
auth()->user()->role->id,
$get('force_upload') ?? false
)->id
);
}
)
->afterStateHydrated(
function (ShowImage $component, Closure $get) {
if ($get('image_id')) {
$image = Image::find($get('image_id'));
$component->state($image->storageLocation->host_name . '/' . $image->file_path);
}
}
),
Forms\Components\FileUpload::make('image_upload')
->afterStateUpdated(
function (Closure $set, Closure $get, TemporaryUploadedFile $state, HandleImagesService $handleImagesService) {
$set(
'image_id',
$handleImagesService->handleImage(
null,
$state,
ModelsNamesWithImages::STATUS_IMAGE,
auth()->user()->role->id,
$get('force_upload') ?? false
)->id
);
}
)
->afterStateHydrated(
function (ShowImage $component, Closure $get) {
if ($get('image_id')) {
$image = Image::find($get('image_id'));
$component->state($image->storageLocation->host_name . '/' . $image->file_path);
}
}
),
$image->storageLocation->host_name . '/' . $image->file_path
$image->storageLocation->host_name . '/' . $image->file_path
this gives the right url
15 replies
FFilament
Created by LancelotGamer on 8/25/2023 in #❓┊help
How can I hydrate FileUpload field with a URL
I tried this code but it didn't work
Forms\Components\FileUpload::make('image')
->afterStateHydrated(
function (FileUpload $component, Closure $get) {
if ($get('image_id')) {
$image = Image::find($get('image_id'))->with('storageLocation')->first();
$component->state([$image->storageLocation->host_name . '/' . $image->file_path]);
}
}
),
Forms\Components\FileUpload::make('image')
->afterStateHydrated(
function (FileUpload $component, Closure $get) {
if ($get('image_id')) {
$image = Image::find($get('image_id'))->with('storageLocation')->first();
$component->state([$image->storageLocation->host_name . '/' . $image->file_path]);
}
}
),
The image dose show in the table
2 replies
FFilament
Created by LancelotGamer on 8/24/2023 in #❓┊help
Image column URL
I have local project that contain the following: Laravel Filament project A Python service that handle image processing, creating thumbnail and saving the images to ftp server or local server etc.. I have an HTTP PHP 7.4.3 Development Server to get the images via URL beside the ftp server My question is: How can I get the images using just a URL like this: http://127.0.0.1:2774/files/eDPEFoHNJu.png
2 replies
FFilament
Created by LancelotGamer on 3/24/2023 in #❓┊help
How can I add a password confirmation to any action
Ex: If an admin wants to make an action, a card will pop up asking the admin to re-enter his password to confirm the action
8 replies
FFilament
Created by LancelotGamer on 3/11/2023 in #❓┊help
How to show / edit pivot attributes in a relation manager
I have two models - Post Model - Comment Model Each of them has belongsToMany() relation Note: Attaching and detaching are working fine
class Post extends Model
{

//...

public function Commects()
{
return $this->belongsToMany(Commect::class, 'post_commect')
->withPivot(['approved_at'])
->using('App\Models\PostCommect');
}
}

class Commect extends Model
{

//...

public function Posts()
{
return $this->belongsToMany(Post:class, 'post_commect')
->withPivot(['approved_at'])
->using('App\Models\PostCommect');
}
}

class PostCommect extends Pivot
{
public function post()
{
return $this->belongsTo(Post:class, 'post_id');
}

public function commect()
{
return $this->belongsTo(Commect::class, 'commect_id');
}
}

class CommentsRelationManager extends RelationManager
{
protected static string $relationship = 'comments';

protected static ?string $recordTitleAttribute = 'body';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('body'), //<----- Comment attribute
Forms\Components\DatePicker::make('approved_at'), //<----- pivot attribute
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('body')->limit(50), //<----- Comment attribute (not showing)
Tables\Columns\TextColumn::make('approved_at'), //<----- pivot attribute (not showing)
])
}
}
class Post extends Model
{

//...

public function Commects()
{
return $this->belongsToMany(Commect::class, 'post_commect')
->withPivot(['approved_at'])
->using('App\Models\PostCommect');
}
}

class Commect extends Model
{

//...

public function Posts()
{
return $this->belongsToMany(Post:class, 'post_commect')
->withPivot(['approved_at'])
->using('App\Models\PostCommect');
}
}

class PostCommect extends Pivot
{
public function post()
{
return $this->belongsTo(Post:class, 'post_id');
}

public function commect()
{
return $this->belongsTo(Commect::class, 'commect_id');
}
}

class CommentsRelationManager extends RelationManager
{
protected static string $relationship = 'comments';

protected static ?string $recordTitleAttribute = 'body';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('body'), //<----- Comment attribute
Forms\Components\DatePicker::make('approved_at'), //<----- pivot attribute
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('body')->limit(50), //<----- Comment attribute (not showing)
Tables\Columns\TextColumn::make('approved_at'), //<----- pivot attribute (not showing)
])
}
}
When I add the edit action Laravel gives me this error Filament\Resources\RelationManagers\RelationManager::Filament\Resources\RelationManagers{closure}(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, null given And is it possible to show pivot attributes along with model attattributes
12 replies