Skip to content

Commit d8f1051

Browse files
committed
fix: parentClass and route name issues
1 parent 7904f15 commit d8f1051

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Supported Laravel Versions:
2727
- v1.x: Laravel 6 and later ([see the source](https://github.com/izniburak/laravel-auto-routes/tree/1.x))
2828

2929
Run the following command directly in your Project path:
30-
```
31-
$ composer require izniburak/laravel-auto-routes
30+
```sh
31+
composer require izniburak/laravel-auto-routes
3232
```
3333
**OR** open your `composer.json` file and add the package like this:
3434
```json
@@ -39,16 +39,16 @@ $ composer require izniburak/laravel-auto-routes
3939
}
4040
```
4141
after run the install command.
42-
```
43-
$ composer install
42+
```sh
43+
composer install
4444
```
4545

4646
The service provider of the Package will be **automatically discovered** by Laravel.
4747

4848
After that, you should publish the config file via following command:
4949

50-
```
51-
$ php artisan vendor:publish --provider="Buki\AutoRoute\AutoRouteServiceProvider"
50+
```sh
51+
php artisan vendor:publish --provider="Buki\AutoRoute\AutoRouteServiceProvider"
5252
```
5353
Greate! You can start to use **Auto Route** Package.
5454

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"php": "^8.1"
2424
},
2525
"require-dev": {
26-
"illuminate/routing": "^10.0",
26+
"illuminate/routing": "^10.0|^11.0",
2727
"phpunit/phpunit": "^10.1"
2828
},
2929
"autoload": {

src/AutoRoute.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,20 @@ public function auto(string $prefix, string $controller, array $options = []): v
7777
$except = $options['except'] ?? [];
7878
$patterns = $options['patterns'] ?? [];
7979

80+
$routeName = trim($options['as'] ?? ($options['name'] ?? trim($prefix, '/')), '.') . '.';
81+
if ($routeName === '.') {
82+
$routeName = '';
83+
}
84+
8085
$this->router->group(
81-
array_merge($options, [
82-
'prefix' => $prefix,
83-
'as' => isset($options['as'])
84-
? "{$options['as']}."
85-
: (isset($options['name'])
86-
? "{$options['name']}."
87-
: trim($prefix, '/') . '.'
88-
),
89-
]),
86+
array_merge($options, ['prefix' => $prefix, 'as' => $routeName]),
9087
function () use ($controller, $only, $except, $patterns) {
9188
[$class, $className] = $this->resolveControllerName($controller);
9289
$classRef = new ReflectionClass($class);
9390
foreach ($classRef->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
9491
// Check the method should be added into Routes or not.
9592
if (in_array($method->class, [BaseController::class, "{$this->namespace}\\Controller"])
96-
|| $method->getDeclaringClass()->getParentClass()->getName() === BaseController::class
93+
|| ($method->getDeclaringClass()->getParentClass() && $method->getDeclaringClass()->getParentClass()->getName() === BaseController::class)
9794
|| !$method->isPublic()
9895
|| str_starts_with($method->name, '__')) {
9996
continue;

0 commit comments

Comments
 (0)