Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. /**
  2. * Register a new wildcard route that returns a view if it exists.
  3. *
  4. * @param string $path
  5. * @param string $viewDirectory
  6. * @param array $data
  7. * @return \Illuminate\Routing\Route
  8. */
  9. \Route::macro('viewDir', function ($path, $viewDirectory = null, $data = []) {
  10. $pathWithSegments = trim($path, '/') . '/{page?}';
  11. $originalPath = $path;
  12. return $this->get($pathWithSegments, function ($path = '') use ($originalPath, $viewDirectory, $data) {
  13. if (is_null($viewDirectory)) {
  14. $viewDirectory = $originalPath;
  15. }
  16. $viewPath = "{$viewDirectory}.{$path}";
  17. if (view()->exists($viewPath)) {
  18. return view($viewPath)->with($data);
  19. }
  20. if (view()->exists($viewPath . '.index')) {
  21. return view($viewPath . '.index')->with($data);
  22. }
  23. abort(404);
  24. })->where('page', '.*');
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement