Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Register a new wildcard route that returns a view if it exists.
- *
- * @param string $path
- * @param string $viewDirectory
- * @param array $data
- * @return \Illuminate\Routing\Route
- */
- \Route::macro('viewDir', function ($path, $viewDirectory = null, $data = []) {
- $pathWithSegments = trim($path, '/') . '/{page?}';
- $originalPath = $path;
- return $this->get($pathWithSegments, function ($path = '') use ($originalPath, $viewDirectory, $data) {
- if (is_null($viewDirectory)) {
- $viewDirectory = $originalPath;
- }
- $viewPath = "{$viewDirectory}.{$path}";
- if (view()->exists($viewPath)) {
- return view($viewPath)->with($data);
- }
- if (view()->exists($viewPath . '.index')) {
- return view($viewPath . '.index')->with($data);
- }
- abort(404);
- })->where('page', '.*');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement