CodingAuthority
CodingAuthority
FFilament
Created by bodhi8370 on 12/15/2023 in #❓┊help
Relationship Does Not Exists
Hi, there is a typo
public function alhusers(): HasOne {
return $this->hasOne('ahlusers::class');
}
public function alhusers(): HasOne {
return $this->hasOne('ahlusers::class');
}
alhusers and ahlusers
20 replies
FFilament
Created by CodingAuthority on 12/15/2023 in #❓┊help
BelongsToMany Relationship Cast Problem on Edit Record
Than i have UsersRelationManager for ProjectResource
class UsersRelationManager extends RelationManager
{
protected static string $relationship = 'users';

public function isReadOnly(): bool
{
return false;
}

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('email')
->required()
->maxLength(255),
Forms\Components\TextInput::make('special_cpi')
->required()
->numeric()
->inputMode('decimal'),
Forms\Components\Select::make('special_status')
->options(ProjectStatus::class)
->required()
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('email')
->columns([
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('special_cpi')
->money('USD'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
Tables\Actions\AttachAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DetachAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DetachBulkAction::make(),
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}
class UsersRelationManager extends RelationManager
{
protected static string $relationship = 'users';

public function isReadOnly(): bool
{
return false;
}

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('email')
->required()
->maxLength(255),
Forms\Components\TextInput::make('special_cpi')
->required()
->numeric()
->inputMode('decimal'),
Forms\Components\Select::make('special_status')
->options(ProjectStatus::class)
->required()
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('email')
->columns([
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('special_cpi')
->money('USD'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
Tables\Actions\AttachAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DetachAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DetachBulkAction::make(),
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}
That's all. I am really sorry for sending more than few messages, discord limits the max characters
6 replies
FFilament
Created by CodingAuthority on 12/15/2023 in #❓┊help
BelongsToMany Relationship Cast Problem on Edit Record
Project Model has Cast and BelongsToMany Relationship
class Project extends Model
{
protected $casts = [
'status' => ProjectStatus::class,
'cpi' => MoneyCast::class,
];

public function users(): BelongsToMany
{
return $this->belongsToMany(User::class)
->using(ProjectUser::class)
->withPivot('pivot_id', 'special_status', 'special_cpi')
->withTimestamps();
}
}
class Project extends Model
{
protected $casts = [
'status' => ProjectStatus::class,
'cpi' => MoneyCast::class,
];

public function users(): BelongsToMany
{
return $this->belongsToMany(User::class)
->using(ProjectUser::class)
->withPivot('pivot_id', 'special_status', 'special_cpi')
->withTimestamps();
}
}
User Model has BelongsToMany Relationship
class User extends Authenticatable
{
public function projects(): BelongsToMany
{
return $this->belongsToMany(Project::class)
->using(ProjectUser::class)
->withPivot('pivot_id', 'special_status', 'special_cpi')
->withTimestamps();
}
}
class User extends Authenticatable
{
public function projects(): BelongsToMany
{
return $this->belongsToMany(Project::class)
->using(ProjectUser::class)
->withPivot('pivot_id', 'special_status', 'special_cpi')
->withTimestamps();
}
}
ProjectUser Model with Casts and other table related data
class ProjectUser extends Pivot
{
protected $primaryKey = 'pivot_id';
public $incrementing = true;
protected $table = 'project_user';
protected $casts = [
'special_status' => ProjectStatus::class,
'special_cpi' => MoneyCast::class,
];
}
class ProjectUser extends Pivot
{
protected $primaryKey = 'pivot_id';
public $incrementing = true;
protected $table = 'project_user';
protected $casts = [
'special_status' => ProjectStatus::class,
'special_cpi' => MoneyCast::class,
];
}
6 replies
FFilament
Created by CodingAuthority on 12/15/2023 in #❓┊help
BelongsToMany Relationship Cast Problem on Edit Record
No description
6 replies