Overview
Core controllers return response contracts that implementResponsable. You can replace any core response by binding its contract to your own class.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Replace and customize HTTP responses in Unleash Commerce Core
Responsable. You can replace any core response by binding its contract to your own class.
namespace App\Http\Responses;
use Esign\UnleashCommerce\Core\Contracts\Http\Responses\ProductResponse as ProductResponseContract;
use Esign\UnleashCommerce\Core\Contracts\Models\Product as ProductContract;
use Inertia\Inertia;
class ProductResponse implements ProductResponseContract
{
public function __construct(protected ProductContract $product) {}
public function toResponse($request)
{
return Inertia::render('Products/Show', [
'product' => $this->product,
'extra' => 'Custom payload',
])->toResponse($request);
}
}
<?php
namespace App\Providers;
use App\Http\Responses\ProductResponse;
use Esign\UnleashCommerce\Core\Contracts\Http\Responses\ProductResponse as ProductResponseContract;
use Illuminate\Support\ServiceProvider;
class UnleashCommerceServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->registerResponses();
}
protected function registerResponses(): void
{
$this->app->bind(
ProductResponseContract::class,
ProductResponse::class
);
}
}
namespace App\Http\Controllers;
use Esign\UnleashCommerce\Core\Contracts\Http\Responses\ProductResponse as ProductResponseContract;
use Esign\UnleashCommerce\Core\Contracts\Models\Product as ProductContract;
use Illuminate\Http\Request;
class ProductController
{
public function show(ProductContract $product, Request $request): ProductResponseContract
{
return app(ProductResponseContract::class, [
'product' => $product,
]);
}
}