Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Http/Requests/InteractWithRepositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function repository($key = null): ?Repository

if (! $repository::authorizedToUseRoute($this)) {
abort(403, __('Unauthorized to use the route :name. Check prefix.', [
'name' => $this->getRequestUri()
'name' => $this->getRequestUri(),
]));
}

Expand Down
11 changes: 4 additions & 7 deletions src/Repositories/WithRoutePrefix.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace Binaryk\LaravelRestify\Repositories;


use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -58,24 +56,23 @@ public static function authorizedToUseRoute(RestifyRequest $request): bool
if ($request->isForRepositoryRequest()) {
// index
if (static::indexPrefix()) {
return $request->is(static::indexPrefix() . '/*');
return $request->is(static::indexPrefix().'/*');
}

if (static::prefix()) {
return $request->is(static::prefix() . '/*');
return $request->is(static::prefix().'/*');
}
} else {
// the rest
return $request->is(static::prefix() . '/*');
return $request->is(static::prefix().'/*');
}

}

protected static function shouldAuthorizeRouteUsage(): bool
{
return collect([
static::prefix(),
static::indexPrefix(),
])->some(fn($prefix) => (bool) $prefix);
])->some(fn ($prefix) => (bool) $prefix);
}
}
1 change: 0 additions & 1 deletion tests/Repositories/RepositoryCustomPrefixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Binaryk\LaravelRestify\Tests\Repositories;

use Binaryk\LaravelRestify\Restify;
use Binaryk\LaravelRestify\Tests\Fixtures\Post\PostRepository;
use Binaryk\LaravelRestify\Tests\IntegrationTest;

Expand Down