Skip to content

Commit 9a2ba5d

Browse files
committed
Check if scout driver is available
1 parent 21b5cf9 commit 9a2ba5d

File tree

7 files changed

+29
-12
lines changed

7 files changed

+29
-12
lines changed

app/Http/Controllers/GlassController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ public function update(int $id, GlassRequest $request): JsonResource
132132
}
133133
}
134134

135-
$glass->cocktails->each(fn ($cocktail) => $cocktail->searchable());
135+
if (!empty(config('scout.driver'))) {
136+
$glass->cocktails->each(fn ($cocktail) => $cocktail->searchable());
137+
}
136138

137139
return new GlassResource($glass);
138140
}

app/Http/Controllers/RatingController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public function rateCocktail(RatingRequest $request, int $id): Response
3939
$request->user()->id
4040
);
4141

42-
$cocktail->searchable();
42+
if (!empty(config('scout.driver'))) {
43+
$cocktail->searchable();
44+
}
4345

4446
return new Response(null, 204);
4547
}
@@ -60,7 +62,9 @@ public function deleteCocktailRating(Request $request, int $id): Response
6062

6163
$cocktail->deleteUserRating($request->user()->id);
6264

63-
$cocktail->searchable();
65+
if (!empty(config('scout.driver'))) {
66+
$cocktail->searchable();
67+
}
6468

6569
return new Response(null, 204);
6670
}

app/Http/Controllers/TagController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ public function update(TagRequest $request, int $id): JsonResource
106106
$tag->save();
107107

108108
$cocktailIds = DB::table('cocktail_tag')->select('cocktail_id')->where('tag_id', $tag->id)->pluck('cocktail_id');
109-
Cocktail::find($cocktailIds)->each(fn ($cocktail) => $cocktail->searchable());
109+
if (!empty(config('scout.driver'))) {
110+
Cocktail::find($cocktailIds)->each(fn ($cocktail) => $cocktail->searchable());
111+
}
110112

111113
return new TagResource($tag);
112114
}
@@ -127,7 +129,9 @@ public function delete(Request $request, int $id): Response
127129

128130
$cocktailIds = DB::table('cocktail_tag')->select('cocktail_id')->where('tag_id', $id)->pluck('cocktail_id');
129131
$tag->delete();
130-
Cocktail::find($cocktailIds)->each(fn ($cocktail) => $cocktail->searchable());
132+
if (!empty(config('scout.driver'))) {
133+
Cocktail::find($cocktailIds)->each(fn ($cocktail) => $cocktail->searchable());
134+
}
131135

132136
return new Response(null, 204);
133137
}

app/Models/Glass.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ public function bar(): BelongsTo
7373

7474
public function delete(): bool
7575
{
76-
$this->cocktails->each(fn ($cocktail) => $cocktail->searchable());
76+
if (!empty(config('scout.driver'))) {
77+
$this->cocktails->each(fn ($cocktail) => $cocktail->searchable());
78+
}
79+
7780
$this->deleteImages();
7881

7982
return parent::delete();

app/Services/BarOptimizerService.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ public function optimize(int $barId): void
7373
}
7474
Log::info('[' . $barId . '] Finished updating ingredient default units.');
7575

76-
/** @phpstan-ignore-next-line */
77-
Cocktail::where('bar_id', $barId)->searchable();
78-
/** @phpstan-ignore-next-line */
79-
Ingredient::where('bar_id', $barId)->searchable();
76+
if (!empty(config('scout.driver'))) {
77+
/** @phpstan-ignore-next-line */
78+
Cocktail::where('bar_id', $barId)->searchable();
79+
/** @phpstan-ignore-next-line */
80+
Ingredient::where('bar_id', $barId)->searchable();
81+
}
8082

8183
Log::info('[' . $barId . '] Finished re-indexing cocktails and ingredients.');
8284
}

app/Services/IngredientService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ public function updateIngredient(int $id, IngredientRequest $dto): Ingredient
198198
});
199199
}
200200

201-
$ingredient->cocktails->each(fn ($cocktail) => $cocktail->searchable());
201+
if (!empty(config('scout.driver'))) {
202+
$ingredient->cocktails->each(fn ($cocktail) => $cocktail->searchable());
203+
}
202204

203205
return $ingredient;
204206
}

config/scout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
|
1616
*/
1717

18-
'driver' => env('SCOUT_DRIVER', 'algolia'),
18+
'driver' => env('SCOUT_DRIVER', null),
1919

2020
/*
2121
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)