How to use the request route parameter in Laravel 5 form request?

How to use the request route parameter in Laravel 5 form request?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Accessing Route Parameters in Laravel Form Request Authorization

In Laravel, the authorize method within a form request class is designed to check permissions before an action is executed. However, a common stumbling block for developers new to the framework occurs when attempting to validate or authorize actions that depend on route parameters, such as the ID of a resource being deleted. You might find yourself in a situation where your controller signature looks like this:

public function destroy($id, DeletePivotRequest $request) {
    // Logic here
}

The controller receives the $id directly from the route binding or parameter, but the DeletePivotRequest::authorize() method is isolated and does not automatically inject that value. Attempting to access global variables or try to parse the URL manually inside the request class is an anti-pattern that leads to fragile code and violates separation of concerns.

To solve this, you must leverage Laravel's dependency injection container. The Illuminate\Http\Request instance available in your form request class provides a convenient way to extract route parameters without needing to pass them explicitly into every single controller action. You can access the specific route parameter by calling route() or by accessing the route() property of the $this->request object if you are passing it as an argument.

Here is how you should structure your DeletePivotRequest class:

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class DeletePivotRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize()
    {
        // Retrieve the ID from the route parameter named 'id'
        $id = $this->route('id');

        // You can also use $this->request->route('id') if not using constructor injection
        // But typically, $this->route() is available directly on the FormRequest
        
        // Perform your authorization logic here. 
        // For example, ensure the user owns the resource before deletion.
        
        return true; // Or false if authorization fails
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules()
    {
        return [
            // 'id' => 'required|integer',
        ];
    }
}

In this implementation, $this->route('id') pulls the value from the route definition. This approach is robust because it decouples the authorization logic from the controller's method signature. You no longer need to pass the $id as a typed parameter to your controller methods if you are strictly using form requests for authorization purposes.

However, there is a significant trade-off to consider regarding how Laravel binds parameters. If your route is defined as Route::delete('resources/{id}', 'ResourceController@destroy'), Laravel automatically resolves the model and passes it as the first argument. In this scenario, passing the ID into the form request via $this->route('id') works perfectly.

The pitfall arises if you change your controller signature to accept the model directly: public function destroy(Resource $resource, DeletePivotRequest $request). In this specific case, the $id variable is no longer explicitly available in the controller's local scope unless you access the property of the resource or re-fetch it. While passing the ID manually is an option, relying on $this->route('id') inside the request class ensures your authorization rules always have access to the intended identifier, regardless of how the controller decides to handle the resource resolution.

This pattern keeps your security checks centralized and consistent. If you need to implement custom logic that depends on route parameters for permission checks, accessing them via the request object is the standard, supported approach in Laravel 5 and beyond. It avoids the need for messy global state management or complex controller-passing hacks.

Our network