]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/TechniqueController.php
random chat buttons
[alttp.git] / app / Http / Controllers / TechniqueController.php
index 59559a94a1883edb46c50c7f71e33cd33f87b072..b88b5a3c21645a94f2370b4ff2b76ab324f96d2a 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,33 @@ 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) {
+                       $view = view('app')
+                               ->with('title', $tech->getTranslatedProperty('title'))
+                               ->with('description', $tech->getTranslatedProperty('short'));
+                       if ($tech->image) {
+                               $view = $view->with('image', url($tech->image));
+                       } else if ($tech->gif) {
+                               $view = $view->with('image', url($tech->gif));
+                       }
+                       return $view;
+               }
+               $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])) {