pmkevinrudd
pmkevinrudd
FFilament
Created by pmkevinrudd on 2/6/2024 in #❓┊help
BelongsTo select save issue
Having an issue with a select input not saving as the correct name, caused by different relationship naming. On create the knowledge_base_category_id select input is correct, when updating it tries to save as category_id. Code breakdown below. I have two models KnowledgeBaseArticle KnowledgeBaseCategory KnowledgeBaseArticle
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

class KnowledgeBaseArticle extends Model
{
use HasFactory;

protected $casts = [
'published_at' => 'datetime',
];

protected $guarded = [];

public function category()
{
return $this->belongsTo(KnowledgeBaseCategory::class, 'knowledge_base_category_id');
}

public function user()
{
return $this->belongsTo(User::class);
}
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

class KnowledgeBaseArticle extends Model
{
use HasFactory;

protected $casts = [
'published_at' => 'datetime',
];

protected $guarded = [];

public function category()
{
return $this->belongsTo(KnowledgeBaseCategory::class, 'knowledge_base_category_id');
}

public function user()
{
return $this->belongsTo(User::class);
}
}
KnowledgeBaseCategory
class KnowledgeBaseCategory extends Model
{
use HasFactory;

protected $guarded = [];

public function articles()
{
return $this->hasMany(KnowledgeBaseArticle::class, 'knowledge_base_category_id');
}
}
class KnowledgeBaseCategory extends Model
{
use HasFactory;

protected $guarded = [];

public function articles()
{
return $this->hasMany(KnowledgeBaseArticle::class, 'knowledge_base_category_id');
}
}
I have the following resource for KnowledgeBaseArticle
public static function form(Form $form): Form
{
return $form
->columns(3)
->schema([
Forms\Components\Section::make('General')
->columnSpan(2)
->columns(2)
->schema([
Forms\Components\TextInput::make('title')
->label('Title')
->live(debounce: 500)
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
if (($get('slug') ?? '') !== Str::slug($old)) {
return;
}

$set('slug', Str::slug($state));
})
->required(),
Forms\Components\TextInput::make('slug'),
Forms\Components\RichEditor::make('content')
->columnSpan(2)
->label('Content')
->required(),
]),
Forms\Components\Section::make('Details')
->columnSpan(1)
->schema([
Forms\Components\Select::make('knowledge_base_category_id')
->label('Category')
->relationship('category', 'title')
->preload()
->createOptionForm([
Forms\Components\TextInput::make('title')
->required(),
Forms\Components\Textarea::make('description'),
])
->searchable()
->required(),
Forms\Components\Select::make('user_id')
->label('Published By')
->searchable()
->relationship('user', 'name')
->nullable(),
Forms\Components\DatePicker::make('published_at')
->label('Publish Date')
->nullable(),
])
]);
}
public static function form(Form $form): Form
{
return $form
->columns(3)
->schema([
Forms\Components\Section::make('General')
->columnSpan(2)
->columns(2)
->schema([
Forms\Components\TextInput::make('title')
->label('Title')
->live(debounce: 500)
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
if (($get('slug') ?? '') !== Str::slug($old)) {
return;
}

$set('slug', Str::slug($state));
})
->required(),
Forms\Components\TextInput::make('slug'),
Forms\Components\RichEditor::make('content')
->columnSpan(2)
->label('Content')
->required(),
]),
Forms\Components\Section::make('Details')
->columnSpan(1)
->schema([
Forms\Components\Select::make('knowledge_base_category_id')
->label('Category')
->relationship('category', 'title')
->preload()
->createOptionForm([
Forms\Components\TextInput::make('title')
->required(),
Forms\Components\Textarea::make('description'),
])
->searchable()
->required(),
Forms\Components\Select::make('user_id')
->label('Published By')
->searchable()
->relationship('user', 'name')
->nullable(),
Forms\Components\DatePicker::make('published_at')
->label('Publish Date')
->nullable(),
])
]);
}
18 replies
FFilament
Created by pmkevinrudd on 11/10/2023 in #❓┊help
Changing login redirect url
Instead of the dashboard being where you land after login, where would you change to land on a resource?
9 replies
FFilament
Created by pmkevinrudd on 10/17/2023 in #❓┊help
Column action documentation
I'm trying to run the code seen here: https://filamentphp.com/docs/3.x/tables/columns/getting-started#running-actions Example code:
php

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\Layout\Split::make([
ImageColumn::make('plate_image')
->width(200)
->height(100)
->action(function (Video $record): void {
$this->dispatch('View Video', video: $record->getKey());
})
])
])
->actions([
ActionGroup::make([
Tables\Actions\Action::make('View Video')
->form([
\App\Forms\Components\Video::make('video_filename')
->label('Video')
])->disabledForm()
])
]);
}
php

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\Layout\Split::make([
ImageColumn::make('plate_image')
->width(200)
->height(100)
->action(function (Video $record): void {
$this->dispatch('View Video', video: $record->getKey());
})
])
])
->actions([
ActionGroup::make([
Tables\Actions\Action::make('View Video')
->form([
\App\Forms\Components\Video::make('video_filename')
->label('Video')
])->disabledForm()
])
]);
}
I get this when clicking on the image column still get redirected to the edit page. Am I doing something wrong here to make the modal appear when clicking on the image instead of redirecting to the edit page?
Using $this when not in object context
Using $this when not in object context
3 replies
FFilament
Created by pmkevinrudd on 9/6/2023 in #❓┊help
Refresh table from an echo event
Is there a way out of the box to listen for echo events on a table and have the table refresh when that event fires? What i'm trying to achieve is only when a record thats visible in the table or new is updated/created it causes a table to refresh. https://filamentphp.com/docs/3.x/tables/advanced#polling-table-content
11 replies