class Post extends Model
{
//...
public function Commects()
{
return $this->belongsToMany(Commect::class, 'post_commect')
->withPivot(['approved_at'])
->using('App\Models\PostCommect');
}
}
class Commect extends Model
{
//...
public function Posts()
{
return $this->belongsToMany(Post:class, 'post_commect')
->withPivot(['approved_at'])
->using('App\Models\PostCommect');
}
}
class PostCommect extends Pivot
{
public function post()
{
return $this->belongsTo(Post:class, 'post_id');
}
public function commect()
{
return $this->belongsTo(Commect::class, 'commect_id');
}
}
class CommentsRelationManager extends RelationManager
{
protected static string $relationship = 'comments';
protected static ?string $recordTitleAttribute = 'body';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('body'), //<----- Comment attribute
Forms\Components\DatePicker::make('approved_at'), //<----- pivot attribute
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('body')->limit(50), //<----- Comment attribute (not showing)
Tables\Columns\TextColumn::make('approved_at'), //<----- pivot attribute (not showing)
])
}
}
class Post extends Model
{
//...
public function Commects()
{
return $this->belongsToMany(Commect::class, 'post_commect')
->withPivot(['approved_at'])
->using('App\Models\PostCommect');
}
}
class Commect extends Model
{
//...
public function Posts()
{
return $this->belongsToMany(Post:class, 'post_commect')
->withPivot(['approved_at'])
->using('App\Models\PostCommect');
}
}
class PostCommect extends Pivot
{
public function post()
{
return $this->belongsTo(Post:class, 'post_id');
}
public function commect()
{
return $this->belongsTo(Commect::class, 'commect_id');
}
}
class CommentsRelationManager extends RelationManager
{
protected static string $relationship = 'comments';
protected static ?string $recordTitleAttribute = 'body';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('body'), //<----- Comment attribute
Forms\Components\DatePicker::make('approved_at'), //<----- pivot attribute
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('body')->limit(50), //<----- Comment attribute (not showing)
Tables\Columns\TextColumn::make('approved_at'), //<----- pivot attribute (not showing)
])
}
}