PHP code example of justbetter / laravel-dynamics-client
1. Go to this page and download the library: Download justbetter/laravel-dynamics-client 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/ */
justbetter / laravel-dynamics-client example snippets
// Will use the default connection.
Customer::query()->first();
// Uses the supplied connection.
Customer::query('other_connection')->first();
'Company' => [
'base_url' => env('DYNAMICS_BASE_URL'),
'version' => env('DYNAMICS_VERSION', 'ODataV4'),
'company' => 'Company Name',
'uuid' => 'Company UUID', // The UUID will be prioritized over the company name
use JustBetter\DynamicsClient\OData\BaseResource;
class Customer extends BaseResource
{
//
}
$salesOrder = SalesOrder::query()->first();
// Get the lines via the "relation" method.
$salesLines = $salesOrder->relation('Relation_Name', SalesLine::class)->get();
// Or use the "lines" helper on the SalesOrder.
$salesLines = $salesOrder->lines('Relation_Name')->get();
Customer::query()
->where('City', '=', 'Alkmaar')
->whereIn('No', ['1000', '2000'])
->dd();
// Customer?$filter=City eq 'Alkmaar' and (No eq '1000' or No eq '2000')
use JustBetter\DynamicsClient\Exceptions\DynamicsException;
use JustBetter\DynamicsClient\Contracts\ClientFactoryContract;
class MyCustomClientFactory implements ClientFactoryContract
{
public function __construct(public string $connection)
{
$config = config('dynamics.connections.'.$connection);
if (! $config) {
throw new DynamicsException(
__('Connection ":connection" does not exist', ['connection' => $connection])
);
}
$this
->header('Authorization', 'Bearer ' . $config['access_token'])
->header('Accept', 'application/json')
->header('Content-Type', 'application/json');
}
...
}
use JustBetter\DynamicsClient\Contracts\ClientFactoryContract;
class AppServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->bind(ClientFactoryContract::class, MyCustomClientFactory::class);
}
}
use JustBetter\DynamicsClient\OData\BaseResource;
BaseResource::fake();