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();
}
}