0

I can serve html files and folders within the public folder in Laravel.

but I want to serve them as view & render them as view,

so I can use The Authentication & Authorization middlewares on them.

either if they were a lot of files, I don't want to write a lot of routes for each file.

miken32
  • 42,008
  • 16
  • 111
  • 154
Abilogos
  • 4,777
  • 2
  • 19
  • 39
  • @manjkiran appathurai : it doesnt, since it doesn't help me to not write hierarchical routes for hierarchical structure – Abilogos Nov 29 '21 at 08:30

1 Answers1

0

The solution for this would be to create static assets under the resources/views like resources/views/static.

for example:

resources/views/static/foo.html
resources/views/static/bar/baz.html

after that I can place a wild-card-like route at my routes file,

then force view-engine to accept html exension, and convert url hierarchy like blade hierarchy


Route::get('/pages/{url?}', function ($url) {
    View::addExtension('html', 'php');
    $viewPath = str_replace(DIRECTORY_SEPARATOR, '.', pathinfo($url, PATHINFO_DIRNAME)) . '.'.pathinfo($url, PATHINFO_FILENAME);
    return View::make('static.'. $viewPath);
})->where('url', '(.*)');
Abilogos
  • 4,777
  • 2
  • 19
  • 39