Tritus
Tritus
FFilament
Created by Tritus on 10/10/2023 in #❓┊help
Change text for buttons "Create" and remove "Create and create another"
Hi everyone, I was pretty sure to have found it the documentation a time ago, but I am not able to see it again. I'm trying to change the label for the "Create" button (replace it with "Save") for Create and Edit pages, and I want to remove the "Create and create another" on the Create page. Can someone help me? Thanks a lot!
13 replies
FFilament
Created by Tritus on 8/4/2023 in #❓┊help
Unable to find component filament.livewire.notifications
Hi, I'm using a custom page and after an object is saved, I redirect to that custom page. However, I always come accross the following error : "Unable to find component : [filament.livewire.notifications]". I suppose there is something missing maybe in my custom page, but I do not find what. Here is my redirect function :
class CreateProjectsType extends CreateRecord
{
protected static string $resource = ProjectsTypeResource::class;

protected function getRedirectUrl(): string
{
return route('projectstype.items.edit', $this->getRecord());
}
}
class CreateProjectsType extends CreateRecord
{
protected static string $resource = ProjectsTypeResource::class;

protected function getRedirectUrl(): string
{
return route('projectstype.items.edit', $this->getRecord());
}
}
And then the custom page called by the router :
<?php
namespace App\Livewire;

use App\Models\Project;
use Filament\Pages\Page;
use Livewire\Attributes\On;
use Livewire\Component;

class Planning extends Page
{
protected static string $view = 'filament.pages.planning';

protected static ?string $title = 'Custom Page Title';

public ?ProjectsType $project;

public $items = [];

#[On('reload-items')]
public function refreshItems()
{
// Some code
}

public static function shouldRegisterNavigation(): bool
{
return false;
}

public function mount(ProjectsType $projectstype)
{
$this->project = $projectstype;
// Some code
self::$title = 'Planning for project type ' . $this->project->name;
}
}
<?php
namespace App\Livewire;

use App\Models\Project;
use Filament\Pages\Page;
use Livewire\Attributes\On;
use Livewire\Component;

class Planning extends Page
{
protected static string $view = 'filament.pages.planning';

protected static ?string $title = 'Custom Page Title';

public ?ProjectsType $project;

public $items = [];

#[On('reload-items')]
public function refreshItems()
{
// Some code
}

public static function shouldRegisterNavigation(): bool
{
return false;
}

public function mount(ProjectsType $projectstype)
{
$this->project = $projectstype;
// Some code
self::$title = 'Planning for project type ' . $this->project->name;
}
}
And to finish, here is the view for this page :
<x-filament-panels::page>
<div>
<div class="w-full text-right">
<x-filament::button color="primary" @click="$dispatch('open-modal', { id: 'add-item' })">
New item
</x-filament::button>
</div>
<x-filament::modal width="5xl" id="add-item">
<!-- Something -->
</x-filament::modal>
<ul class="divide-y divide-gray-100">
<!-- HTML blabla -->
</ul>
</div>
</x-filament-panels::page>
<x-filament-panels::page>
<div>
<div class="w-full text-right">
<x-filament::button color="primary" @click="$dispatch('open-modal', { id: 'add-item' })">
New item
</x-filament::button>
</div>
<x-filament::modal width="5xl" id="add-item">
<!-- Something -->
</x-filament::modal>
<ul class="divide-y divide-gray-100">
<!-- HTML blabla -->
</ul>
</div>
</x-filament-panels::page>
Do you see where the issue could come from? Thanks!
3 replies
FFilament
Created by Tritus on 8/2/2023 in #❓┊help
[V3] Blade components do not have the good colour
Hi, I'm using Filament v3 and I'm trying to use the blade components, especially the button one. I'm experiencing an issue with that : in fact, when I change the primary colour of my theme, it is correctly reflected on all Filament parts of my dashboard EXCEPT on the components I manually use. Here is my AdminPanelProvider :
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->colors([
'primary' => '#09F',
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
// ...
])
->authMiddleware([
Authenticate::class,
])
->viteTheme('resources/css/filament/admin/theme.css');
}
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->colors([
'primary' => '#09F',
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
// ...
])
->authMiddleware([
Authenticate::class,
])
->viteTheme('resources/css/filament/admin/theme.css');
}
And how I use the button :
<x-filament::button @click="$dispatch('open-modal', { id: 'add-item' })">
New item
</x-filament::button>
<x-filament::button @click="$dispatch('open-modal', { id: 'add-item' })">
New item
</x-filament::button>
The button will stay orange, whereas the rest of the website is using correctly the primary colour #09F. Any idea?
19 replies
FFilament
Created by Tritus on 7/27/2023 in #❓┊help
wire:sortable callback has no effect in custom page
Hi guys, I created a custom Filament page. Inside, I have the following content :
<x-filament::page>
<ul wire:sortable="updateTaskOrder">
@foreach ($items as $task)
<li wire:sortable.item="{{ $task->id }}" wire:key="task-{{ $task->id }}">
<h4 wire:sortable.handle>{{ $task->title }}</h4>
<button wire:click="removeTask({{ $task->id }})">Remove</button>
</li>
@endforeach
</ul>
</x-filament::page>
<x-filament::page>
<ul wire:sortable="updateTaskOrder">
@foreach ($items as $task)
<li wire:sortable.item="{{ $task->id }}" wire:key="task-{{ $task->id }}">
<h4 wire:sortable.handle>{{ $task->title }}</h4>
<button wire:click="removeTask({{ $task->id }})">Remove</button>
</li>
@endforeach
</ul>
</x-filament::page>
However, the callback method passed to wire:sortable is NEVER called. I do not know why. Is it a problem with Filament livewire component?
9 replies
FFilament
Created by Tritus on 7/12/2023 in #❓┊help
Repeater and pivot table
Hi, I'm facing an issue with Repeater and a BelongsToMany Relationship. Here's my Project model :
class Project extends Model
{
public function members(): BelongsToMany
{
return $this->belongsToMany(User::class);
}
}
class Project extends Model
{
public function members(): BelongsToMany
{
return $this->belongsToMany(User::class);
}
}
My pivot table, called "project_user", has a "project_role" column. Then I have in my EditProject (App\Filament\Resources\ProjectResource\Pages\EditProject) the following Repeater :
Repeater::make('members')->schema([

Select::make('user_id')->label('Member email')->options(User::all()->pluck('email', 'id'))->searchable()->required(),

Select::make('project_role')->options(...)->required()
])->createItemButtonLabel('Add member')
Repeater::make('members')->schema([

Select::make('user_id')->label('Member email')->options(User::all()->pluck('email', 'id'))->searchable()->required(),

Select::make('project_role')->options(...)->required()
])->createItemButtonLabel('Add member')
I'd like the "project_role" select to automatically fill this pivot column, however it does not work, it tries to fill my "users" table. Any idea?
4 replies
FFilament
Created by Tritus on 7/3/2023 in #❓┊help
Relationship "id", fillable and saveRelationships
Hi everyone, There is probably something I misuderstand. I have a "Course" entity and a "CourseCategory" entity. My relationship is as simple as :
public function course_category(): BelongsTo
{
return $this->belongsTo(CourseCategory::class);
}
public function course_category(): BelongsTo
{
return $this->belongsTo(CourseCategory::class);
}
In my CourseResource I have the following select :
Forms\Components\Select::make('course_category_id')
->relationship('course_category', 'title')
->searchable()
->required(),
Forms\Components\Select::make('course_category_id')
->relationship('course_category', 'title')
->searchable()
->required(),
And in my CreateCourse :
protected function handleRecordCreation(array $data): Model
{
return auth()->user()->courses()->create($data);
}
protected function handleRecordCreation(array $data): Model
{
return auth()->user()->courses()->create($data);
}
But if I submit my form, I always get "Field 'course_category_id' doesn't have a default value". The issue disappears if I add "course_category_id" in the $fillable of Course, but I do not like that idea.
I'm seeing there is the "saveRelationships(); " who is called automatically, but I'm not sure to see how it works because if I add course_category_id in the $fillable, it is totally useless, and if not, I have the issue shown above. Can someone help me understand what's the best way to deal with that ? Thanks !
8 replies