diff --git a/app/Http/Controllers/Admin/MountController.php b/app/Http/Controllers/Admin/MountController.php index ce5dbc859..79c729976 100644 --- a/app/Http/Controllers/Admin/MountController.php +++ b/app/Http/Controllers/Admin/MountController.php @@ -105,20 +105,6 @@ class MountController extends Controller $model = (new Mount())->fill($request->validated()); $model->forceFill(['uuid' => Uuid::uuid4()->toString()]); - foreach (Mount::$invalidSourcePaths as $path) { - if (Str::startsWith($model->source, $path)) { - $this->alert->danger('"' . $path . '" cannot be used as a source path.')->flash(); - return redirect()->route('admin.mounts'); - } - } - - foreach (Mount::$invalidTargetPaths as $path) { - if (Str::startsWith($model->target, $path)) { - $this->alert->danger('"' . $path . '" cannot be used as a target path.')->flash(); - return redirect()->route('admin.mounts'); - } - } - $model->saveOrFail(); $mount = $model->fresh(); @@ -142,23 +128,7 @@ class MountController extends Controller return $this->delete($mount); } - $mount->forceFill($request->validated()); - - foreach (Mount::$invalidSourcePaths as $path) { - if (Str::startsWith($mount->source, $path)) { - $this->alert->danger('"' . $path . '" cannot be used as a source path.')->flash(); - return redirect()->route('admin.mounts.view', $mount->id); - } - } - - foreach (Mount::$invalidTargetPaths as $path) { - if (Str::startsWith($mount->target, $path)) { - $this->alert->danger('"' . $path . '" cannot be used as a target path.')->flash(); - return redirect()->route('admin.mounts.view', $mount->id); - } - } - - $mount->save(); + $mount->forceFill($request->validated())->save(); $this->alert->success('Mount was updated successfully.')->flash(); diff --git a/app/Models/Mount.php b/app/Models/Mount.php index a77181d8e..69c47f01c 100644 --- a/app/Models/Mount.php +++ b/app/Models/Mount.php @@ -2,6 +2,8 @@ namespace Pterodactyl\Models; +use Illuminate\Validation\Rules\NotIn; + /** * @property int $id * @property string $uuid @@ -63,6 +65,20 @@ class Mount extends Model 'user_mountable' => 'sometimes|boolean', ]; + /** + * Implement language verification by overriding Eloquence's gather + * rules function. + */ + public static function getRules() + { + $rules = parent::getRules(); + + $rules['source'][] = new NotIn(Mount::$invalidSourcePaths); + $rules['target'][] = new NotIn(Mount::$invalidSourcePaths); + + return $rules; + } + /** * Disable timestamps on this model. *