Skip to content

Commit

Permalink
Allow same URL for different sites (multi-site) - Fix #171
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Sep 28, 2024
1 parent a767076 commit e329ac2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Blueprints/RedirectBlueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Rias\StatamicRedirect\Blueprints;

use Closure;
use Illuminate\Support\Facades\Session;
use Rias\StatamicRedirect\Enums\MatchTypeEnum;
use Rias\StatamicRedirect\Facades\Redirect;
use Statamic\Facades\Blueprint;
Expand All @@ -24,11 +25,13 @@ public function __invoke()
'instructions' => 'Enter the URL pattern that Redirect should match. This matches against the path only e.g.: Exact Match: `/recipes/`, or RegEx Match: `.*RecipeID=(.*)`',
'listable' => true,
'validate' => ['required', 'string', function (string $attribute, $value, Closure $fail) {
$selectedSite = Session::get('statamic.cp.selected-site', Site::current()->handle());

$existing = Redirect::query()
->where('source', $value)
->when(request()->route('id'), fn ($query) => $query->where('id', '!=', request()->route('id')))
->where('site', Site::current()->handle())
->count() > 0;
->where('site', $selectedSite)
->first();

if ($existing) {
$fail(__("This source already has a redirect associated with it."));
Expand Down

0 comments on commit e329ac2

Please sign in to comment.