Matteo G
Matteo G
Explore posts from servers
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
CDCloudflare Developers
Created by Matteo G on 8/24/2023 in #general-help
Routing subdomain to path on main domain
Hello all, I am trying to modify a cname record for one of my domains. I would like to have blog.example.com redirect to example.com/blog. I think I should be able to do so using DNS, right ?
2 replies