class TechniqueController extends Controller
{
+ public function byType(Request $request, $type) {
+ $techs = Technique::where('index', true)->where('type', '=', $type);
+ $this->applyFilter($request, $techs);
+ return $techs->get()->toJson();
+ }
+
+ public function byTypeAndName(Request $request, $type, $name) {
+ $tech = Technique::where('type', '=', $type)->where('name', '=', $name)->firstOrFail();
+ $this->authorize('view', $tech);
+ $tech->load(['chapters', 'relations']);
+ return $tech->toJson();
+ }
+
public function forMap($map) {
$techs = TechniqueMap::with(['technique', 'technique.relations'])->where('map', '=', $map);
}
public function search(Request $request) {
+ $techs = Technique::where('index', '=', 1);
+ $this->applyFilter($request, $techs);
+ return $techs->get()->toJson();
+ }
+
+ public function single(Request $request, Technique $tech) {
+ $this->authorize('view', $tech);
+ $tech->load(['chapters', 'relations']);
+ return $tech->toJson();
+ }
+
+ protected function applyFilter(Request $request, Builder $query) {
$validatedData = $request->validate([
'phrase' => 'string|nullable',
'ruleset' => 'array|nullable',
'type' => 'string|nullable',
]);
- $techs = Technique::where('index', '=', 1);
-
if (!empty($validatedData['type'])) {
- $techs = $techs->where('type', '=', $validatedData['type']);
+ $query->where('type', '=', $validatedData['type']);
}
if (!empty($validatedData['phrase'])) {
$search = $validatedData['phrase'];
- $techs = $techs->where(function (Builder $query) use ($search) {
+ $query->where(function (Builder $query) use ($search) {
$query->where('title', 'LIKE', '%'.$search.'%')
->orWhere('short', 'LIKE', '%'.$search.'%');
});
$any = $com || $owg || $mg || $nl;
$all = $com && $owg && $mg && $nl;
if ($any && !$all) {
- $techs->where(function(Builder $query) use ($com, $owg, $mg, $nl) {
+ $query->where(function(Builder $query) use ($com, $owg, $mg, $nl) {
$query->whereNull('rulesets');
if ($com) {
$query->orWhere('rulesets->competitive', '=', true);
});
}
}
-
- return $techs->get()->toJson();
- }
-
- public function single(Request $request, Technique $tech) {
- $this->authorize('view', $tech);
- $tech->load(['chapters', 'relations']);
- return $tech->toJson();
}
}
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('techniques', function(Blueprint $table) {
+ $table->dropUnique(['name']);
+ $table->unique(['type', 'name']);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('techniques', function(Blueprint $table) {
+ $table->dropUnique(['type', 'name']);
+ $table->unique(['name']);
+ });
+ }
+};
import axios from 'axios';
+import PropTypes from 'prop-types';
import React, { useEffect, useState } from 'react';
import { Helmet } from 'react-helmet';
import { withTranslation } from 'react-i18next';
import { getLanguages, getMatchedLocale, getTranslation } from '../../helpers/Technique';
import i18n from '../../i18n';
-const Technique = () => {
+const Technique = ({ type }) => {
const params = useParams();
const { name } = params;
const ctrl = new AbortController();
setLoading(true);
axios
- .get(`/api/tech/${name}`, { signal: ctrl.signal })
+ .get(`/api/pages/${type}/${name}`, { signal: ctrl.signal })
.then(response => {
setError(null);
setLoading(false);
return () => {
ctrl.abort();
};
- }, [name]);
+ }, [name, type]);
if (loading) {
return <Loading />;
</ErrorBoundary>;
};
+Technique.propTypes = {
+ type: PropTypes.string,
+};
+
export default withTranslation()(Technique);