Skip to content

Commit 66b9169

Browse files
committed
Cleanup code in MountController.php, again.
1 parent 050075b commit 66b9169

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

app/Http/Controllers/Admin/MountController.php

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,6 @@ public function create(MountFormRequest $request)
105105
$model = (new Mount())->fill($request->validated());
106106
$model->forceFill(['uuid' => Uuid::uuid4()->toString()]);
107107

108-
foreach (Mount::$invalidSourcePaths as $path) {
109-
if (Str::startsWith($model->source, $path)) {
110-
$this->alert->danger('"' . $path . '" cannot be used as a source path.')->flash();
111-
return redirect()->route('admin.mounts');
112-
}
113-
}
114-
115-
foreach (Mount::$invalidTargetPaths as $path) {
116-
if (Str::startsWith($model->target, $path)) {
117-
$this->alert->danger('"' . $path . '" cannot be used as a target path.')->flash();
118-
return redirect()->route('admin.mounts');
119-
}
120-
}
121-
122108
$model->saveOrFail();
123109
$mount = $model->fresh();
124110

@@ -142,23 +128,7 @@ public function update(MountFormRequest $request, Mount $mount)
142128
return $this->delete($mount);
143129
}
144130

145-
$mount->forceFill($request->validated());
146-
147-
foreach (Mount::$invalidSourcePaths as $path) {
148-
if (Str::startsWith($mount->source, $path)) {
149-
$this->alert->danger('"' . $path . '" cannot be used as a source path.')->flash();
150-
return redirect()->route('admin.mounts.view', $mount->id);
151-
}
152-
}
153-
154-
foreach (Mount::$invalidTargetPaths as $path) {
155-
if (Str::startsWith($mount->target, $path)) {
156-
$this->alert->danger('"' . $path . '" cannot be used as a target path.')->flash();
157-
return redirect()->route('admin.mounts.view', $mount->id);
158-
}
159-
}
160-
161-
$mount->save();
131+
$mount->forceFill($request->validated())->save();
162132

163133
$this->alert->success('Mount was updated successfully.')->flash();
164134

app/Models/Mount.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Pterodactyl\Models;
44

5+
use Illuminate\Validation\Rules\NotIn;
6+
57
/**
68
* @property int $id
79
* @property string $uuid
@@ -63,6 +65,20 @@ class Mount extends Model
6365
'user_mountable' => 'sometimes|boolean',
6466
];
6567

68+
/**
69+
* Implement language verification by overriding Eloquence's gather
70+
* rules function.
71+
*/
72+
public static function getRules()
73+
{
74+
$rules = parent::getRules();
75+
76+
$rules['source'][] = new NotIn(Mount::$invalidSourcePaths);
77+
$rules['target'][] = new NotIn(Mount::$invalidSourcePaths);
78+
79+
return $rules;
80+
}
81+
6682
/**
6783
* Disable timestamps on this model.
6884
*

0 commit comments

Comments
 (0)