Calden
Calden
FFilament
Created by Calden on 4/2/2024 in #❓┊help
Column relationships problem
i got the correct result when i use the following code :
Tables\Columns\TextColumn::make('enseignants')
->getStateUsing(function (Model $record) {
$name_list = array();
$list = $record->matiere->enseignants()->wherePivot('session_id', $record->session_id)->get()->toArray();
foreach ($list as $subarray) {
if (isset($subarray["prenom_nom"])) {
$name_list[] = $subarray["prenom_nom"];
}
}
return $name_list;
})
->label('Enseignants')
->badge()
->placeholder('Aucun')
->searchable(),
])
Tables\Columns\TextColumn::make('enseignants')
->getStateUsing(function (Model $record) {
$name_list = array();
$list = $record->matiere->enseignants()->wherePivot('session_id', $record->session_id)->get()->toArray();
foreach ($list as $subarray) {
if (isset($subarray["prenom_nom"])) {
$name_list[] = $subarray["prenom_nom"];
}
}
return $name_list;
})
->label('Enseignants')
->badge()
->placeholder('Aucun')
->searchable(),
])
But why i cant use this ?
Tables\Columns\TextColumn::make('enseignants.prenom_nom')
Tables\Columns\TextColumn::make('enseignants.prenom_nom')
9 replies
FFilament
Created by Calden on 4/2/2024 in #❓┊help
Column relationships problem
I'm on the "matieresSession" relationmanager of the "MatiereResource" where "Matiere" model is :
class Matiere extends Model
{
use HasFactory;

public function enseignants(): BelongsToMany
{
return $this->belongsToMany(Enseignant::class, 'enseignant_matiere')->orderBy('prenom_nom');
}

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

public function matieresSession(): HasMany
{
return $this->hasMany(MatiereSession::class);
}
class Matiere extends Model
{
use HasFactory;

public function enseignants(): BelongsToMany
{
return $this->belongsToMany(Enseignant::class, 'enseignant_matiere')->orderBy('prenom_nom');
}

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

public function matieresSession(): HasMany
{
return $this->hasMany(MatiereSession::class);
}
9 replies
FFilament
Created by Calden on 4/2/2024 in #❓┊help
Column relationships problem
No description
9 replies
FFilament
Created by Calden on 4/2/2024 in #❓┊help
Column relationships problem
when i have "Tables\Columns\TextColumn::make('enseignants.prenom')", i get the error :
9 replies
FFilament
Created by Calden on 4/2/2024 in #❓┊help
Column relationships problem
No description
9 replies
FFilament
Created by Calden on 4/2/2024 in #❓┊help
Column relationships problem
Ok, i have delete records, i now have just one "MatiereSession record, when i add a Tables\Columns\TextColumn::make('matiere.nom') i have the name of the "matiere" so there is datas for matiere ? When i have only "Tables\Columns\TextColumn::make('enseignants')", i have :
9 replies