3 namespace App\Http\Controllers;
5 use App\Models\Technique;
6 use Illuminate\Database\Eloquent\Builder;
7 use Illuminate\Http\Request;
9 class TechniqueController extends Controller
12 public function search(Request $request) {
13 $validatedData = $request->validate([
14 'phrase' => 'string|nullable',
15 'type' => 'string|nullable',
18 $techs = Technique::where('index', '=', 1);
20 if (!empty($validatedData['type'])) {
21 $techs = $techs->where('type', '=', $validatedData['type']);
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.'%');
32 return $techs->get()->toJson();
35 public function single(Request $request, Technique $tech) {
36 $this->authorize('view', $tech);
37 $tech->load('chapters');
38 return $tech->toJson();