]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/TechniqueController.php
serverside tech init
[alttp.git] / app / Http / Controllers / TechniqueController.php
index 59559a94a1883edb46c50c7f71e33cd33f87b072..1d51aff846f6f48910be8ae82c0e5e0d5483838a 100644 (file)
@@ -6,6 +6,7 @@ use App\Models\Technique;
 use App\Models\TechniqueMap;
 use App\Models\TechniqueTranslation;
 use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\ModelNotFoundException;
 use Illuminate\Http\Request;
 
 class TechniqueController extends Controller
@@ -68,6 +69,27 @@ class TechniqueController extends Controller
                return $result->toJson();
        }
 
+       public function web(Request $request, $type, $name) {
+               $tech = Technique::where('type', '=', $type)->where('name', '=', $name)->first();
+               if ($tech) {
+                       return view('app')
+                               ->with('title', $tech->getTranslatedProperty('title'))
+                               ->with('description', $tech->getTranslatedProperty('short'));
+               }
+               $url_map = [
+                       'dungeon' => 'dungeons',
+                       'location' => 'locations',
+                       'mode' => 'modes',
+                       'ruleset' => 'rulesets',
+                       'tech' => 'tech',
+               ];
+               $tech = Technique::where('name', '=', $name)->whereIn('type', array_keys($url_map))->first();
+               if ($tech && isset($url_map[$tech->type])) {
+                       return redirect('/'.$url_map[$tech->type].'/'.$tech->name);
+               }
+               throw new ModelNotFoundException();
+       }
+
        private function applyLocalizedValues($validatedData, $content) {
                foreach (['attribution', 'description', 'short', 'title'] as $name) {
                        if (isset($validatedData[$name])) {