You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I create models: Clinic, Service, ClinicService (pivot) + ClinicServiceTranslable
Clinic model
class Clinic extends Model
{
use HasFactory, Translatable;
protected $fillable = [
'is_active',
];
public $translatedAttributes = [
'name',
];
public function services(): belongsToMany
{
return $this->belongsToMany(Service::class)
->withPivot('price');
}
}
Service Model
class Service extends Model
{
use HasFactory, Translatable;
protected $fillable = [
'is_active'
];
public $translatedAttributes = [
'name',
];
protected function casts(): array
{
return [
'is_active' => 'boolean',
];
}
public function clinics(): BelongsToMany
{
return $this->belongsToMany(Clinic::class)
->withPivot('price');
}
}
ClinicService Model
class ClinicService extends Pivot implements TranslatableContract
{
use HasFactory, Translatable;
protected $translationForeignKey = 'clinic_service_id';
public $incrementing = true;
protected $fillable = [
'clinic_id',
'service_id',
'price',
];
public $translatedAttributes = [
'comment',
];
}
ClinicServiceTranslable Model
class ClinicServiceTranslation extends Model
{
public $timestamps = false;
protected $fillable = [
'comment',
];
}
I recommend you to use a regular model with belongsTo/hasMany relationships and utilize hasManyThrough if you want.
But pivots aren't made to handle advanced logic.
If you go with a dedicated ClinicServiceConfig or whatever you like as a regular model everything will just work smoothly. And by eager loading it also shouldn't have too much of an impact (if any) on performance.
I create models: Clinic, Service, ClinicService (pivot) + ClinicServiceTranslable
Clinic model
Service Model
ClinicService Model
ClinicServiceTranslable Model
I write connections in the controller
and I get the response:
Help me get comment from pivot translable model clinic_service_translation...
In the end I want to get this pivot responce:
The text was updated successfully, but these errors were encountered: