1. Go to this page and download the library: Download codebar-ag/laravel-odoo 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/ */
codebar-ag / laravel-odoo example snippets
use CodebarAg\Odoo\OdooConnector;
$connector = new OdooConnector(
baseUrl: 'https://your-odoo-instance.com',
apiKey: 'your-api-key',
db: 'your-database', // optional
maxRedirects: 5, // optional — max HTTP redirects to follow (default 5)
timeout: 15.0, // optional — request timeout in seconds (default 15, 0 = no timeout)
);
use CodebarAg\Odoo\Facades\Odoo;
$response = Odoo::health();
$response->isHealthy(); // bool
// Check if the Odoo instance is reachable
$response = $connector->health();
$response->isHealthy(); // bool
// Get the Odoo server version
$response = $connector->version();
$response->serverVersion(); // ?string e.g. "17"
$response->serie(); // ?string e.g. "17.0"
// List all available databases
$response = $connector->databases();
$response->databases(); // array<string>
// Get the currently authenticated user
$response = $connector->getUser(
fields: ['name', 'email'], // optional — omit to get the default field set
domain: [], // optional
limit: 1, // optional, default 1
);
$user = $response->dto(); // ?UserDto (id, name, lang)
// Get a user by their Odoo ID
$response = $connector->getUserById(
uid: 1,
fields: ['name', 'email'], // optional
);
// Get the authenticated user's context (timezone, language)
$response = $connector->getUserContext();
// Get an employee by their Odoo user ID
$response = $connector->getEmployeeByUserId(
userId: 1,
fields: ['name', 'job_title'], // optional — omit to get all fields
limit: 1, // optional, default 1
);
$response->dto(); // ?EmployeeDto
// Get fields for a specific model
$response = $connector->getFields(
model: 'account.move',
attributes: ['string', 'type'], // optional — field meta-attributes to return
);
$response->fields(); // array<string, FieldDto>
// Get all fields across all models
$response = $connector->getAllFields();
$response->fields(); // array<string, FieldDto>
// Check permissions for a model and operation
$response = $connector->getPermissions(
model: 'project.project',
operation: 'read', // read, write, create, unlink
);
$response->allowed(); // bool