Skip to content

Commit 87d4929

Browse files
committed
- Add support for Laravel 5.4
- Return `error-404` class when route is a 404 - Cleanup This work is derived from the following merge request: #4 (comment) Props to GitHub user yemenifree: https://github.com/yemenifree
1 parent ff8308a commit 87d4929

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
}
1616
},
1717
"require": {
18-
"illuminate/support": "5.3.*"
18+
"illuminate/support": "5.3.*||5.4.*"
1919
}
2020
}

src/Generators/FullRoutePath.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,29 @@ class FullRoutePath extends GeneratorAbstract
2525
{
2626
public function generateClassName()
2727
{
28-
$path = $this->getRoute()->getPath();
28+
/**
29+
* Return `error-404` when no route exists.
30+
*/
31+
$route = $this->getRoute();
32+
33+
if (!$route) {
34+
return 'error-404';
35+
}
36+
37+
/**
38+
* Return null if no path exists (such as viewing a homepage or index page)
39+
*/
40+
$path = $route->uri();
2941

30-
// Return early if no route path exists (such as viewing homepage/index)
3142
if ('/' === $path) {
3243
return null;
3344
}
3445

46+
/**
47+
* Convert the full route path to a class name.
48+
*/
3549
// Remove route parameters. product_id is removed here: `controller/product/{product_id}`
36-
$className = preg_replace("/\{([^}]+)\}/", '', $this->getRoute()->getPath());
50+
$className = preg_replace("/\{([^}]+)\}/", '', $path);
3751

3852
// Remove characters that aren't alpha, numeric, or dashes
3953
$className = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $className);

0 commit comments

Comments
 (0)