1. Go to this page and download the library: Download grebo87/laravel-vtex-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
grebo87 / laravel-vtex-api example snippets
namespace App\Http\Controllers;
use Grebo87\LaravelVtexApi\Services\Catalog\BrandService;
use Grebo87\LaravelVtexApi\Data\Catalog\Brands\BrandCreateData;
class BrandController extends Controller
{
private BrandService $brandService;
public function __construct(BrandService $brandService)
{
$this->brandService = $brandService;
}
public function index()
{
// Obtener lista de marcas
return $this->brandService->getBrandList();
}
public function show(int $id)
{
// Obtener marca por ID
return $this->brandService->getBrand($id);
}
public function store(array $data)
{
// Crear una nueva marca usando DTO
$brandData = new BrandCreateData(
name: $data['name'],
text: $data['text'] ?? null,
keywords: $data['keywords'] ?? [],
siteTitle: $data['siteTitle'] ?? null,
active: $data['active'] ?? true,
menuHome: $data['menuHome'] ?? false,
score: $data['score'] ?? null
);
// Usar el DTO con el servicio
return $this->brandService->createBrand($brandData);
}
}
namespace App\Http\Controllers;
use Grebo87\LaravelVtexApi\Facades\Brand;
class BrandController extends Controller
{
public function index()
{
// Obtener lista de marcas
return Brand::getBrandList();
}
public function show(int $id)
{
// Obtener marca por ID
return Brand::getBrand($id);
}
}