fumi
fumi

Reputation: 13

Laravel route allow any parameter not working

Any help why this is not working,I am using Laravel 5.4 version ,this is are my routes

app\Providers\RouteServiceProvider.php

public function map()
{
    $this->mapWebRoutes();
    $this->mapExampleRoutes();
}
protected function mapExampleRoutes()
{
    Route::prefix('example')
         ->middleware('example')
         ->namespace($this->namespace.'\\Examle')
         ->group(base_path('routes/example.php'));
}

routes\example.php

Route::get('/{any}', function () {
    return view('example.app');
})->where('any', '.*');

$ php artisan route:list

+--------+-----------+-----------------+------+----------+-------------+
| Domain | Method    | URI             | Name | Action   | Middleware  |
+--------+-----------+-----------------+------+----------+-------------+
|        | GET|HEAD  | /               |      | Closure  | web         |
|        | GET|HEAD  | example/{any}   |      | Closure  | example     |
+--------+-----------+-----------------+------+----------+-------------+

The problem is when I try to access /example it returns not found (NotFoundHttpException) , other routes are working , for example, /example/login .
any idea why this one is not working ?

Upvotes: 0

Views: 356

Answers (1)

online Thomas
online Thomas

Reputation: 9391

Route::get('{any?}', function () {
    return view('example.app');
})->where('any', '.*');

I removed the leading slash (/) and added a question mark (?) to indicate the slug is optional.

Upvotes: 0

Related Questions