- How do I install google/common-protos in a Laravel app?
- Install it with Composer by running composer require google/common-protos in your Laravel project. You should also ensure the google/protobuf runtime is required, typically with composer require google/protobuf. The package is autoloaded through Composer and does not require a Laravel service provider or migrations.
- What is google/common-protos used for in Laravel?
- It provides generated PHP classes for Google's common Protocol Buffer types used across Google APIs, such as API annotations and shared protobuf messages. Laravel applications use it when integrating with Google Cloud services, gRPC APIs, or JSON payloads based on Google API contracts. It is not an Eloquent replacement and does not provide ORM models.
- Does google/common-protos support Laravel 10 or Laravel 11?
- google/common-protos has no Laravel-specific framework constraints, so it can work with Laravel 10, Laravel 11, or other versions when your PHP and google/protobuf requirements are satisfied. Check the package composer.json for current PHP constraints and run integration tests in your CI pipeline. Because it is framework-agnostic, Laravel compatibility mainly depends on Composer resolution and runtime support.
- Do I need google/protobuf installed separately with google/common-protos?
- Yes, the generated classes depend on the Protocol Buffers PHP runtime, so you should require google/protobuf alongside google/common-protos. The assessment notes google/protobuf v4+ as the runtime dependency. Composer may resolve it automatically, but declaring it explicitly in your Laravel composer.json makes the dependency clear.
- Can I use google/common-protos for gRPC and REST or JSON in Laravel?
- Yes, protobuf messages can be serialized and deserialized for gRPC or encoded as JSON using google/protobuf's JSON support. Laravel's HTTP layer can accept JSON requests and pass payloads into generated protobuf classes. There is no native Laravel Protobuf validation layer, so you should add middleware, form requests, or DTO mapping as needed.
- How do I validate protobuf messages in Laravel?
- Decode incoming data with the generated protobuf class and catch protobuf exceptions, then convert failures into Laravel validation or HTTP errors. You can wrap decoding in a FormRequest, middleware, or dedicated DTO so controllers receive clean input. Laravel does not ship built-in Protobuf schema validation rules, so custom validation or schema checks are usually required.
- Is google/common-protos compatible with Eloquent models?
- No, Protobuf messages are not Eloquent models and are not directly compatible with Laravel's ORM or query builder. You should map protobuf messages to DTOs or custom repository objects before persisting data with Eloquent. This keeps your Google API payload contracts separate from your database models.
- What are production concerns when using google/common-protos in Laravel?
- Benchmark protobuf serialization and deserialization on latency-sensitive endpoints because it adds CPU overhead compared with plain JSON. Protobuf schema evolution can also affect API contracts, so pin package versions and use backward-compatible changes where possible. Protobuf decode errors can be opaque, so wrap exceptions and log enough context for debugging.
- Are there alternatives to google/common-protos for Laravel protobuf support?
- Alternatives depend on your use case: you can use google/protobuf directly with your own generated classes, combine it with grpc/grpc for gRPC transport, or use REST/JSON clients for Google APIs. However, google/common-protos is the canonical Composer package for Google's shared common protobuf types. It is not a general Laravel ORM or validation package, so alternatives usually solve different layers of the stack.
- How is google/common-protos maintained and versioned?
- google/common-protos is part of the Google Cloud PHP ecosystem and is published on Packagist under the Apache 2.0 license. The project states that the generated classes are stable and will not change in backwards-incompatible ways. Support requests and contributions should be directed to the google-cloud-php project rather than treated as a Laravel-specific package.