Download the PHP package justbetter/laravel-dynamics-client without Composer
On this page you can find all versions of the php package justbetter/laravel-dynamics-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download justbetter/laravel-dynamics-client
More information about justbetter/laravel-dynamics-client
Files in justbetter/laravel-dynamics-client
Package laravel-dynamics-client
Short Description A client to connect with Microsoft Dynamics
License MIT
Homepage https://github.com/justbetter/laravel-dynamics-client
Informations about the package laravel-dynamics-client
Laravel Dynamics Client
This package will connect you to your Microsoft Dynamics web services via OData. Custom web services can easily be implemented and mapped to your liking. It uses the HTTP client of Laravel which means that you can easily fake requests when writing tests.
The way we interact with OData has been inspired by Laravel's Query Builder.
Installation
Install the composer package.
Setup
Publish the configuration of the package.
Configuration
Add your Dynamics credentials in the .env
:
Be sure the DYNAMICS_PAGE_SIZE
is set equally to the Max Page Size
under OData Services
in the configuration of
Dynamics. This is crucial for the functionalities of the lazy
method of the QueryBuilder
.
Authentication
Note: Be sure that Dynamics has been properly configured for OData.
This package uses NTLM authentication by default. If you are required to use basic auth or OAuth you can change this in
your .env
.
OAuth
To setup OAuth add the following to your .env
When using D365 cloud with Microsoft identity platform your redirect uri will be: https://login.microsoftonline.com/<tenant>/oauth2/v2.0/token
and your base url should be https://api.businesscentral.dynamics.com/v2.0/<tenant>/<environment>
.
Connections
Multiple connections are supported. You can easily update your dynamics
configuration to add as many connections as
you wish.
By default, the client will use the company
field to select the Dynamics company.
If you wish to use the company's UUID you can simply add an uuid
field:
Adding web services
Adding a web service to your configuration is easily done. Start by creating your own resource class to map te data to.
Primary Key
By default, the primary key of a resource will default to No
as a string. You can override this by supplying the
variable $primaryKey
.
Data Casting
Fields in resources will by default be treated as a string. For some fields, like a line number, this should be casted to an integer.
Registering Your Resource
Lastly, you should register your resource in your configuration file to let the package know where the web service is located. This should correspond to the service name configured in Dynamics.
If your resource class name is the same as the service name, no manual configuration is needed.
Note: Make sure your web service is published.
Query Builder
Querying data is easily done using the QueryBuilder.
Using the get
method will only return the first result page. If you wish to efficiently loop through all records,
use lazy
instead.
See the QueryBuilder
class for all available methods.
Relations
Any relations published on a page can be accessed as well using the resource.
Note that the relation
method itself returns an instance of a query builder. This means that you can add additional where-clauses like you would be able to on a regular resource.
Creating records
Create a new record.
Updating records
Update an existing record.
Deleting records
Delete a record.
Debugging
If you wish to review your query before you sent it, you may want to use the dd
function on the builder.
Commands
You can run the following command to check if you can successfully connect to Dynamics.
Extending
If needed, it is possible to extend the provided ClientFactory
class by creating your own. You must implement the ClientFactoryContract
interface and its methods.
You will then need to bind your custom factory as the implementation of the contract, in any of your ServiceProvider
register method :
Fake requests to Dynamics
When writing tests you may find yourself in the need of faking a request to Dynamics. Luckily, this packages uses the HTTP client of Laravel to make this very easy.
In order to fake all requests to Dynamics, you can call the method fake
on any resource.
The
fake
method will fake all requests to Dynamics, not just the endpoint of the used resource.
This method will fake the Dynamics configuration and removes sensitive information like usernames and passwords. Only the company name will remain in order to easily test with multiple connections.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Vincent Boon
- Ramon Rietdijk
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-dynamics-client with dependencies
justbetter/odata-client Version ^1.3
laravel/framework Version ^10.0|^11.0