-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
145 additions
and
54 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
app/Core/Domains/MinecraftCoordinate/ValidatesCoordinates.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Core\Domains\MinecraftCoordinate; | ||
|
||
/** | ||
* A set of validation rules for a Minecraft coordinate | ||
*/ | ||
trait ValidatesCoordinates | ||
{ | ||
protected array $coordinateRules = [ | ||
'world' => ['required', 'string'], | ||
'x' => ['required' ,'numeric'], | ||
'y' => ['required', 'numeric'], | ||
'z' => ['required', 'numeric'], | ||
'pitch' => ['required', 'numeric'], | ||
'yaw' => ['required', 'numeric'], | ||
]; | ||
|
||
protected array $optionalCoordinateRules = [ | ||
'world' => ['string'], | ||
'x' => ['numeric'], | ||
'y' => ['numeric'], | ||
'z' => ['numeric'], | ||
'pitch' => ['numeric'], | ||
'yaw' => ['numeric'], | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
app/Http/Controllers/Manage/Minecraft/MinecraftBuildController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Manage\Minecraft; | ||
|
||
use App\Core\Domains\MinecraftCoordinate\ValidatesCoordinates; | ||
use App\Http\Controllers\WebController; | ||
use App\Models\MinecraftBuild; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Validator; | ||
use Illuminate\Validation\Rule; | ||
|
||
class MinecraftBuildController extends WebController | ||
{ | ||
use ValidatesCoordinates; | ||
|
||
public function index(Request $request) | ||
{ | ||
$builds = MinecraftBuild::orderBy('name', 'asc') | ||
->with('player') | ||
->paginate(100); | ||
|
||
return view('manage.pages.minecraft-builds.index') | ||
->with(compact('builds')); | ||
} | ||
|
||
public function create(Request $request) | ||
{ | ||
$build = new MinecraftBuild(); | ||
|
||
return view('manage.pages.minecraft-builds.create') | ||
->with(compact('build')); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$validator = Validator::make($request->all(), [ | ||
'name' => ['required', 'string', 'alpha_dash', Rule::unique(MinecraftBuild::tableName())], | ||
...$this->coordinateRules, | ||
]); | ||
|
||
if ($validator->fails()) { | ||
return redirect()->back() | ||
->withErrors($validator) | ||
->withInput(); | ||
} | ||
|
||
MinecraftBuild::create($validator->validated()); | ||
|
||
return redirect(route('manage.minecraft.builds.index')); | ||
} | ||
|
||
public function edit(MinecraftBuild $build) | ||
{ | ||
return view('manage.pages.minecraft-builds.edit') | ||
->with(compact('build')); | ||
} | ||
|
||
public function update(Request $request, MinecraftBuild $build) | ||
{ | ||
$validator = Validator::make($request->all(), [ | ||
'name' => ['required', 'string', 'alpha_dash', Rule::unique(MinecraftBuild::tableName())->ignore($build)], | ||
...$this->coordinateRules, | ||
]); | ||
|
||
if ($validator->fails()) { | ||
return redirect()->back() | ||
->withErrors($validator) | ||
->withInput(); | ||
} | ||
|
||
$build->update($validator->validated()); | ||
|
||
return redirect(route('manage.minecraft.builds.index')); | ||
} | ||
|
||
public function destroy(Request $request, MinecraftBuild $build) | ||
{ | ||
$build->delete(); | ||
|
||
return redirect(route('manage.minecraft.builds.index')); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...lers/Manage/MinecraftConfigController.php → ...e/Minecraft/MinecraftConfigController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters