Looking to hire Laravel developers? Try LaraJobs

laravel-protocontroller maintained by goed

Description
Add Route::protocontroller() for protobuf-over-HTTP resource controllers with FormRequest reuse in Laravel.
Last update
2026/07/25 23:43 (dev-main)
License
Links
Downloads
0

Comments
comments powered by Disqus

Laravel ProtoController

A Laravel package providing a Route::protocontroller() macro for protobuf-over-HTTP resource controllers with FormRequest reuse.

Installation

composer require teunw/laravel-protocontroller

Usage

Register protobuf resource routes with message types and FormRequest bindings:

Route::protocontroller('users', UserController::class, [
    'messages' => [
        'store' => CreateUserRequest::class,
        'update' => UpdateUserRequest::class,
    ],
    'form_requests' => [
        'store' => UserFormRequest::class,
        'update' => UserFormRequest::class,
    ],
    'responses' => [
        'index' => UserCollectionResponse::class,
        'show' => UserResponse::class,
        'store' => UserResponse::class,
        'update' => UserResponse::class,
    ],
]);

The macro auto-registers protobuf.decode and protobuf.encode middleware aliases.

Publish the config:

php artisan vendor:publish --tag=protocontroller-config

How it works

  1. Incoming requests are intercepted by the protobuf.decode middleware, which deserializes the protobuf body into a Laravel-friendly structure.
  2. If a form_request is mapped for the action, validation runs against the decoded data via a standard FormRequest.
  3. The controller receives a clean ProtobufRequest with validated data.
  4. The response returned by the controller is serialized back to protobuf by the protobuf.encode middleware using the mapped response class.