This is an approach to get the solution of this problem: Imagine that you want to get all files inside a subdirectory and you want to show the url like: yoursite.com/files/folders/first
. But you need also to go to yoursite.com/files/folders/second/inside
.
How can you achieve that?
With the Laravel Regular Expression Constraint
Route::get('/files/{path?}', 'MyController@view')->where('path', '.*');
This will handle:
yoursite.com/files
yoursite.com/files/first
yoursite.com/files/folders/first
yoursite.com/files/folders/second/inside
yoursite.com/files/demo/what/im/doing
And in the controller you only need to get it like this:
public function view($path = null)
{
dump($path);
// Result:
// $path = null;
// $path = first
// $path = folders/first
// $path = folders/second/inside
// $path = demo/what/im/doing
}