Positiverain
Positiverain
FFilament
Created by Positiverain on 3/26/2024 in #❓┊help
Advanced toggle column to a table
ToggleColumn::make('collected')
ToggleColumn::make('collected')
My database table doesn't have an is_collected column. Instead, I have a collected_by column (foreign key to a collectors table) and a collected_at timestamp. How can I customize the ToggleColumn to update the collected_by and collected_at columns when toggled on, ideally setting collected_by to auth()->user()->collector_id? By default the toggle sets is_collected to 1 but that column does not exist.
4 replies
FFilament
Created by Positiverain on 2/24/2024 in #❓┊help
How do I fix Enum could not be converted into string when using export action?
enum CitizenStatus: string implements HasColor, HasLabel
{
case UNCHECKED = "Unchecked";

case CHECKED = "Checked";

case REJECTED = "Rejected";

case ACCEPTED = 'Accepted';

case FINALIZED = "Finalized";

case VOTED = "Voted";

public function getColor(): string|array|null
{
return match ($this) {
self::ACCEPTED => Color::hex('#00ff00'),
self::REJECTED => Color::hex('#ff0000'),
self::UNCHECKED => Color::hex('#808080'),
self::CHECKED => Color::hex('#00cdff'),
self::FINALIZED => Color::hex('#999100'),
self::VOTED => Color::hex('#0000ff')
};
}


public function getLabel(): ?string
{
return $this->name;
}
}
enum CitizenStatus: string implements HasColor, HasLabel
{
case UNCHECKED = "Unchecked";

case CHECKED = "Checked";

case REJECTED = "Rejected";

case ACCEPTED = 'Accepted';

case FINALIZED = "Finalized";

case VOTED = "Voted";

public function getColor(): string|array|null
{
return match ($this) {
self::ACCEPTED => Color::hex('#00ff00'),
self::REJECTED => Color::hex('#ff0000'),
self::UNCHECKED => Color::hex('#808080'),
self::CHECKED => Color::hex('#00cdff'),
self::FINALIZED => Color::hex('#999100'),
self::VOTED => Color::hex('#0000ff')
};
}


public function getLabel(): ?string
{
return $this->name;
}
}
public static function getColumns(): array
{
return [
ExportColumn::make('status')
]
}
public static function getColumns(): array
{
return [
ExportColumn::make('status')
]
}
I want to know how to format the state of the enum without the "could not be converted to string" error. Its the $state itself that is in type string throwing the error. Without the $state in the ->state(function ($state) { function it works well.
protected $casts = [
'status' => CitizenStatus::class,
];
protected $casts = [
'status' => CitizenStatus::class,
];
^ I don't think this is relevant but here is the cast
1 replies
FFilament
Created by Positiverain on 2/7/2024 in #❓┊help
Custom Page - How do I show confirmation dialog on Submit?
Also how do I modify the confirmation dialog? Is this even possible in filament v3? I am using use InteractsWithForms . If I use submit, there isn't any confirmation modals/dialog, the action just happens. The ->form([]) of the action also doesn't work. Only thing the action can do is ->submit() Adding a use InteractsWithActions Action to the Page with the page view can do what I want, but the original form of the page isn't validated when using this action.
2 replies
FFilament
Created by Positiverain on 1/29/2024 in #❓┊help
Filament Resource Create/Edit BadMethodCallException Call to undefined method HasMany::associate()
I have a User model as well as a Patch model, every patch HasMany users. What I am trying to achieve is: I want to add Users to Patch. Code:
class User extends Authenticatable
{
protected $fillable = [
'name',
'email',
'password',
'patch_no'
];
//....

//....
public function patch(): BelongsTo
{
return $this->belongsTo(Patch::class);
}
}

class Patch extends Model
{
use HasFactory;

protected $fillable = ['code'];

public function users(): HasMany
{
return $this->hasMany(User::class);
}

}
class User extends Authenticatable
{
protected $fillable = [
'name',
'email',
'password',
'patch_no'
];
//....

//....
public function patch(): BelongsTo
{
return $this->belongsTo(Patch::class);
}
}

class Patch extends Model
{
use HasFactory;

protected $fillable = ['code'];

public function users(): HasMany
{
return $this->hasMany(User::class);
}

}
User migration:
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->foreignId('patch_id')->nullable()->constrained('patches');
$table->rememberToken();
$table->timestamps();
});
}
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->foreignId('patch_id')->nullable()->constrained('patches');
$table->rememberToken();
$table->timestamps();
});
}
Patch migration
Schema::create('patches', function (Blueprint $table) {
$table->id();
$table->string('code');
$table->timestamps();
});
Schema::create('patches', function (Blueprint $table) {
$table->id();
$table->string('code');
$table->timestamps();
});
After this I created a filament-resource: PatchResource. Inside the form I did:
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('code')
->required()
->maxLength(255),
Forms\Components\Select::make('users')
->relationship('users', 'name')
->multiple()
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('code')
->required()
->maxLength(255),
Forms\Components\Select::make('users')
->relationship('users', 'name')
->multiple()
]);
}
What did I do wrong here?
1 replies
FFilament
Created by Positiverain on 1/5/2024 in #❓┊help
How do I make a scrollable section for my form?
No description
2 replies
FFilament
Created by Positiverain on 10/6/2023 in #❓┊help
What's the difference between Tables\Actions\CreateAction and Actions\CreateAction?
One has
namespace Filament\Tables\Actions;

use Closure;
use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Forms\Form;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Support\Arr;
namespace Filament\Tables\Actions;

use Closure;
use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Forms\Form;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Support\Arr;
and the other has
namespace Filament\Actions;

use Closure;
use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Form;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
namespace Filament\Actions;

use Closure;
use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Form;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
Both are having class CreateAction extends Action. I want to use the same functions for ->using(function(*stuffs*) { method of both CreateActions. One of the create action is in the Resource page empty state actions and the other one is in the ManageResource page header. Is there a way to do so?
2 replies
FFilament
Created by Positiverain on 10/2/2023 in #❓┊help
How to add a custom 'CreateRecord Page' to the sidebar navigation?
If I use
->navigation(function (NavigationBuilder $builder): NavigationBuilder {
return $builder->items([...]);
});
->navigation(function (NavigationBuilder $builder): NavigationBuilder {
return $builder->items([...]);
});
I am replacing the default navigation items, including those that are added through plugins. Is there a method I can use with$builder->items([...this_method_calls_default_nav_items()...]) so that I can retrieve the default navigation items?
5 replies
FFilament
Created by Positiverain on 8/30/2023 in #❓┊help
How to setup email verification after the email has been changed?
I am using
return $panel->emailVerification()
return $panel->emailVerification()
on my AdminPanelServiceProvider. Email verification is perfectly working after registering a new user. In the MyProfile page used by the filament-breezy, the user can change their email and I have made it so that the email_verified_at is set to null when the email is different from the previous email, that is before the user email is updated. I can't find a way to verify email for a second time, after changing the email.
1 replies
FFilament
Created by Positiverain on 6/17/2023 in #❓┊help
Eloquent Builder with relationships
I could use $user->hasRole('admin') to identify admins. But filament uses query builder for generating tables: parent::getEloquentQuery(). How do I make it so that parent::getEloquentQuery would generate table with only admin records? ->with('roles') isn't working. (I am using spatie permissions)
8 replies
FFilament
Created by Positiverain on 6/17/2023 in #❓┊help
How to use two forms for two models in one resource? Is it even possible?
Noob here. Maybe I am not using the best practices, but I have a User model (which has username, password, email etc) and a UserDetails model (which has full names, departments, whatsoever). In the same resource I want to make it so that when adding a User using create User, There's one form for username, email and password, there is a next button which would switch to UserDetails form. Only after completing all the required fields it would be possible to submit the form.
4 replies