Skip to content

Commit

Permalink
fix: 500 on edit vehicle page
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed May 11, 2024
1 parent 9ae2e4b commit 7a5947e
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class GroundVehicle extends Vehicle
/**
* Adds the global Ground Vehicle Scope
*/
protected static function boot()
protected static function boot(): void
{
parent::boot();

static::addGlobalScope(
'size',
function (Builder $builder) {
static function (Builder $builder) {
$builder->has('groundVehicles');
}
);
Expand Down
87 changes: 6 additions & 81 deletions app/Models/StarCitizen/Vehicle/Vehicle/Vehicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,16 @@ class Vehicle extends HasTranslations implements HasChangelogsInterface
'deleting' => ModelUpdating::class,
];

/**
* @return HasMany
*/
public function translations()
public function translations(): HasMany
{
return $this->hasMany(VehicleTranslation::class);
}

/**
* @return HasMany
*/
public function skus()
public function skus(): HasMany
{
return $this->hasMany(VehicleSku::class);
}

/**
* @return HasManyThrough
*/
public function translationChangelogs(): HasManyThrough
{
return $this->hasManyThrough(
Expand All @@ -134,59 +125,31 @@ public function translationChangelogs(): HasManyThrough
)->where('changelog_type', VehicleTranslation::class);
}

/**
* The Vehicle Foci
*
* @return BelongsToMany
*/
public function foci()
public function foci(): BelongsToMany
{
return $this->belongsToMany(Focus::class, 'vehicle_vehicle_focus');
}

/**
* The Vehicle Manufacturer
*
* @return BelongsTo
*/
public function manufacturer(): BelongsTo
{
return $this->belongsTo(Manufacturer::class);
}

/**
* The Vehicle Production Status
*
* @return BelongsTo
*/
public function productionStatus(): BelongsTo
{
return $this->belongsTo(ProductionStatus::class, 'production_status_id');
}

/**
* The Vehicle Production Note
*
* @return BelongsTo
*/
public function productionNote(): BelongsTo
{
return $this->belongsTo(ProductionNote::class, 'production_note_id');
}

/**
* The Vehicle Role Type
*
* @return BelongsTo
*/
public function type(): BelongsTo
{
return $this->belongsTo(Type::class);
}

/**
* @return BelongsToMany
*/
public function components(): BelongsToMany
{
return $this->belongsToMany(Component::class, 'vehicle_component')
Expand All @@ -201,11 +164,6 @@ public function components(): BelongsToMany
);
}

/**
* Get Components keyed by component class
*
* @return array
*/
public function componentsByClass(): array
{
$components = $this->components
Expand All @@ -227,21 +185,11 @@ function (Component $component) use (&$components) {
return $components;
}

/**
* Ships
*
* @return mixed
*/
public function ships()
{
return $this->size()->ship();
}

/**
* The Vehicle Size
*
* @return BelongsTo
*/
public function size(): BelongsTo
{
return $this->belongsTo(Size::class);
Expand Down Expand Up @@ -309,8 +257,6 @@ public function getScLengthAttribute($length)

/**
* Unpacked Data
*
* @return HasOne
*/
public function unpacked(): HasOne
{
Expand All @@ -324,8 +270,6 @@ public function unpacked(): HasOne

/**
* Unpacked Data
*
* @return HasOne
*/
public function sc(): HasOne
{
Expand All @@ -337,41 +281,22 @@ public function sc(): HasOne
->withDefault();
}


/**
* Ground Vehicles
*
* @return mixed
*/
public function groundVehicles()
{
return $this->size()->groundVehicle();
}

/**
* Use Vehicle Class in Children
*
* @return string
*/
public function getMorphClass()
public function getMorphClass(): string
{
return self::class;
}

/**
* Hardcoded to fix Child Problems
*
* @return string
*/
public function getForeignKey()
public function getForeignKey(): string
{
return 'vehicle_id';
}

/**
* {@inheritdoc}
*/
public function getRouteKeyName()
public function getRouteKeyName(): string
{
return 'slug';
}
Expand Down
Loading

0 comments on commit 7a5947e

Please sign in to comment.