]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/TechniqueController.php
expand tech
[alttp.git] / app / Http / Controllers / TechniqueController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Models\Technique;
6 use Illuminate\Database\Eloquent\Builder;
7 use Illuminate\Http\Request;
8
9 class TechniqueController extends Controller
10 {
11
12         public function search(Request $request) {
13                 $validatedData = $request->validate([
14                         'phrase' => 'string|nullable',
15                         'type' => 'string|nullable',
16                 ]);
17
18                 $techs = Technique::where('index', '=', 1);
19
20                 if (!empty($validatedData['type'])) {
21                         $techs = $techs->where('type', '=', $validatedData['type']);
22                 }
23
24                 if (!empty($validatedData['phrase'])) {
25                         $search = $validatedData['phrase'];
26                         $techs = $techs->where(function (Builder $query) use ($search) {
27                                 $query->where('title', 'LIKE', '%'.$search.'%')
28                                 ->orWhere('short', 'LIKE', '%'.$search.'%');
29                         });
30                 }
31
32                 return $techs->get()->toJson();
33         }
34
35         public function single(Request $request, Technique $tech) {
36                 $this->authorize('view', $tech);
37                 $tech->load('chapters');
38                 return $tech->toJson();
39         }
40
41 }