Matteo G
Matteo G
Explore posts from servers
FFilament
Created by Matteo G on 11/8/2024 in #❓┊help
Custom Table Name in RelationManager ?
Hey all, is there a way to change with table the relationmanager should query? Tried using the modifyQueryUsing, but it looks like it prefills that value...
2 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
Hey all, I'm working on an admin section for my portfolio page. The data is from a bunch of Markdown files with some frontmatter; this frontmatter has been converted and stored as json in a sqlite database. When editing the Project, I chose to display the frontmatter with a KeyValue form component. After trying to save an instance without changing the values (meaning they should be valid), I get the following error:
Filament\Forms\Components\KeyValue::Filament\Forms\Components\{closure}(): Argument #1 ($value) must be of type ?string, array given
Filament\Forms\Components\KeyValue::Filament\Forms\Components\{closure}(): Argument #1 ($value) must be of type ?string, array given
Could it be that an array value is incompatible with the KeyValue component? Or am I doing something wrong ?
35 replies
FFilament
Created by Matteo G on 8/10/2024 in #❓┊help
Getting owner record in custom association action
Hello all, I have a book and story tables with a pivot table between the two. I have relationship manager to handle associating and dissociating books and stories. But the pivot table also has other data that needs to be entered when creating an association (order). So I have overridden the form for the associate action like so:
Tables\Actions\AssociateAction::make()
->form([
Forms\Components\Select::make('story_id')->options(Story::query()->pluck('name', 'id'))->required()->label('Story'),
Forms\Components\TextInput::make('order')->numeric()->required()->label('Order'),
]),
Tables\Actions\AssociateAction::make()
->form([
Forms\Components\Select::make('story_id')->options(Story::query()->pluck('name', 'id'))->required()->label('Story'),
Forms\Components\TextInput::make('order')->numeric()->required()->label('Order'),
]),
I am now trying to save all this stuff, but I cannot seem to retrieve the Book I'm currently editing inside the action. Is there a way to do so?
4 replies
FFilament
Created by Matteo G on 8/4/2024 in #❓┊help
Custom Pages and Widgets without resources
Hello everyone, I'm rebuilding my new Portfolio in Laravel and would like to keep my collection of md articles without having to store them in a database. I'd like to have some data in a filament admin section (alongside other data) and be able to do basic CRUD operations on those articles. Is there a way to do so and have some widgets (like a count or else) using this data (kind of like a custom Resource) or do I have to do everything manually ? Don't know if I explained myself correctly, but hopefully someone can help me ?
5 replies
FFilament
Created by Matteo G on 7/10/2024 in #❓┊help
Relation Manager and HasManyThrough: General error: 1 no such column on one of the models
Hello everyone, I'm building a library management system using filament and I'm trying to add relation manager to handle the intermediate tables that I need but I must be doing something wrong... The error message is: SQLSTATE[HY000]: General error: 1 no such column: chapters.chapter_story_id I have a Chapter defined like this: migration:
public function up(): void
{
Schema::create('chapters', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
public function up(): void
{
Schema::create('chapters', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
model:
class Chapter extends Model
{
use HasFactory;

protected $fillable = ['name'];

public function stories(): HasManyThrough
{
return $this->hasManyThrough(Story::class, ChapterStory::class);
}
}
class Chapter extends Model
{
use HasFactory;

protected $fillable = ['name'];

public function stories(): HasManyThrough
{
return $this->hasManyThrough(Story::class, ChapterStory::class);
}
}
And a Story defined like this: migration:
public function up(): void
{
Schema::create('stories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description');
$table->foreignIdFor(Language::class);
$table->timestamps();
});
}
public function up(): void
{
Schema::create('stories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description');
$table->foreignIdFor(Language::class);
$table->timestamps();
});
}
model
class Story extends Model
{
use HasFactory;

protected $fillable = ["name", "description", "language_id"];

public function books(): BelongsToMany
{
return $this->belongsToMany(Book::class);
}

public function language(): BelongsTo
{
return $this->belongsTo(Language::class);
}

public function chapters(): HasManyThrough
{
return $this->hasManyThrough(Chapter::class, ChapterStory::class);
}
}
class Story extends Model
{
use HasFactory;

protected $fillable = ["name", "description", "language_id"];

public function books(): BelongsToMany
{
return $this->belongsToMany(Book::class);
}

public function language(): BelongsTo
{
return $this->belongsTo(Language::class);
}

public function chapters(): HasManyThrough
{
return $this->hasManyThrough(Chapter::class, ChapterStory::class);
}
}
And I have an intermediate table called ChapterStory: migration:
public function up(): void
{
Schema::create('chapter_stories', function (Blueprint $table) {
$table->id();
$table->integer('order');
$table->foreignIdFor(Chapter::class);
$table->foreignIdFor(Story::class);
$table->timestamps();
});
}
public function up(): void
{
Schema::create('chapter_stories', function (Blueprint $table) {
$table->id();
$table->integer('order');
$table->foreignIdFor(Chapter::class);
$table->foreignIdFor(Story::class);
$table->timestamps();
});
}
model:
class ChapterStory extends Model
{
use HasFactory;

protected $fillable = ['order', 'chapter_id', 'story_id'];

public function chapter(): BelongsTo
{
return $this->belongsTo(Chapter::class);
}

public function story(): BelongsTo
{
return $this->belongsTo(Story::class);
}
}
class ChapterStory extends Model
{
use HasFactory;

protected $fillable = ['order', 'chapter_id', 'story_id'];

public function chapter(): BelongsTo
{
return $this->belongsTo(Chapter::class);
}

public function story(): BelongsTo
{
return $this->belongsTo(Story::class);
}
}
I haven't modified the relation manager:
class ChaptersRelationManager extends RelationManager
{
protected static string $relationship = 'chapters';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}
class ChaptersRelationManager extends RelationManager
{
protected static string $relationship = 'chapters';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}
Am I doing something wrong ?
6 replies
FFilament
Created by Matteo G on 6/6/2024 in #❓┊help
Saving Optional Relationship to db does not persist
Edit: This is not solved, only halfway there :( Hey all, I've been trying my hand at Laravel and filament for the last couple of weeks and am stuck on something: I have two entities, Book and BookPoster. Both have their foreign_key value set as nullable (because a book might not have a poster at creation). The BookResource's form looks as follows:
return $form
->schema([
Forms\Components\TextInput::make('title')->required(),
Forms\Components\Select::make('book_poster_id')->relationship(name:"poster", titleAttribute: "name")->label("Poster")
->createOptionForm([
Forms\Components\TextInput::make('name')->required(),
Forms\Components\FileUpload::make('poster_path')->required()
])
]);
return $form
->schema([
Forms\Components\TextInput::make('title')->required(),
Forms\Components\Select::make('book_poster_id')->relationship(name:"poster", titleAttribute: "name")->label("Poster")
->createOptionForm([
Forms\Components\TextInput::make('name')->required(),
Forms\Components\FileUpload::make('poster_path')->required()
])
]);
When selecting a BookPoster from the list, the value does not get persisted in database. Do you know what I might be doing wrong?
33 replies