Skip to content

API Request route parameter #58016

@cage81

Description

@cage81

Laravel Version

12.40.2

PHP Version

8.4.15

Database Driver & Version

MySql 9.1.0 on Debian 13

Description

In a previous Laravel version (10.48.29) i created a custom middleware to catch a specific value in the api request path. This, in the handle method, made use of the following:

$request->route('company')

It doesn't work in the newest Laravel version (12.40.2)

Steps To Reproduce

In brief:

laravel new myproject

php artisan install:api

php artisan make:middleware ApiRouteCheck
  • Added the custom middleware in the bootstrap/app.php:

use App\Http\Middleware\ApiRouteCheck;

and:

->withMiddleware(function (Middleware $middleware): void {
    $middleware->append(ApiRouteCheck::class);
})
  • Inside the created middleware, in the handle method, the same:

$request->route('company')

is empty.

Have I missed something else or is it a bug?
Is there another way to read the value in the newer Laravel version?

Thanks, kind regards.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions