PHPackages                             ahmedwaleed/soquel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ahmedwaleed/soquel

ActiveLibrary[Database &amp; ORM](/categories/database)

ahmedwaleed/soquel
==================

An ORM solution for Salesforce Object Query Language (SOQL)

v1.2.2(5y ago)42523[1 PRs](https://github.com/AhmadWaleed/soquel/pulls)MITPHPPHP ^7.4|^8.0CI failing

Since Jan 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/AhmadWaleed/soquel)[ Packagist](https://packagist.org/packages/ahmedwaleed/soquel)[ Docs](https://github.com/AhmadWaleed/soquel)[ GitHub Sponsors](https://github.com/:vendor_name)[ RSS](/packages/ahmedwaleed-soquel/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (5)Versions (7)Used By (0)

[Salesforce Object Query Language (SOQL)](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm) Package For Laravel
===================================================================================================================================================================

[](#salesforce-object-query-language-soql-package-for-laravel)

[![Laravel](https://camo.githubusercontent.com/3f0ad6cc438aa5e759af91d3e8c589a3b085c017be725d9860e3b9c73fedafc5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382e302d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](http://laravel.com)

Laravel SOQL query builder provides a convenient, fluent interface to creating, updating, [SOQL](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm) queries and fetching records from salesforce.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- Laravel &gt;= 8
- [omniphx/forrest](https://github.com/omniphx/forrest) &gt;= 2.\*

> This Package uses [omniphx/forrest](https://github.com/omniphx/forrest) package as salesforce client to fetch records from salesforce, please refer to package github page for installation and configuration guide.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require ahmedwaleed/soquel
```

Optionally, you can publish the config file of package.

```
php artisan vendor:publish --provider="Omniphx\Forrest\Providers\Laravel\ForrestServiceProvider::class"
```

Set following config with your salesforce credentials.

```
'credentials' => [
    // Required:
    'consumerKey' => env('SF_CONSUMER_KEY'),
    'consumerSecret' => env('SF_CONSUMER_SECRET'),
    'callbackURI' => env('SF_CALLBACK_URI'),
    'loginURL' => env('SF_LOGIN_URL'),

    // Only required for UserPassword authentication:
    'username' => env('SF_USERNAME'),
    // Security token might need to be ammended to password unless IP Address is whitelisted
    'password' => env('SF_PASSWORD'),
]
```

Update the storage type to `Session` or `Cache`, only these storage types are suppored at this time.

```
'storage'        => [
    'type'          => 'cache', // Options include: 'session', 'cache', 'object'
    'path'          => 'forrest_', // unique storage path to avoid collisions
    'expire_in'     => 60, // number of minutes to expire cache/session
    'store_forever' => false, // never expire cache/session
]
```

Basic Usage
-----------

[](#basic-usage)

The content of config file will be published at `config/soquel.php`

- Retrieving All Rows From A Object

```
use AhmadWaleed\Soquel\SOQL;

echo SOQL::object('Account')->select('Id', 'Name')->toSOQL();

// Output: SELECT Id, Name FROM Account
```

- Where Clauses

```
SOQL::object('Account')->select('Id', 'Name')->where('Id', '=', 's3dty')->toSOQL();
SOQL::object('Account')->select('Id', 'Name')->where('Name', 'Like', '%john%')->toSOQL();
```

- Additional Where Clauses

```
SOQL::object('Account')->select('Id', 'Name')->where('Id', '=', 's3dty')->orWhere('Id', '=', '2abc')->toSOQL();
SOQL::object('Account')->select('Id', 'Name')->whereIn('Id', ['s3dty', 'ty4ii'])->toSOQL();
SOQL::object('Account')->select('Id', 'Name')->whereNull('Name')->toSOQL();
SOQL::object('Account')->select('Id', 'Name')->whereNotNull('Name')->toSOQL();
SOQL::object('Account')->select('Id', 'Name')->whereRaw("DISTANCE(Contact__r.Geolocation__c, GEOLOCATION(15.623,35.949), 'km') < 1000")->toSOQL();
```

- Select Sub Query

```
SOQL::object('Account')->select('Id', 'Name')->selectSub(SOQL::object('Contact')->select('Id', 'Name'))->toSOQL();
```

- Subquery Where Clauses

```
SOQL::object('Account')->select('Id')->whereIn('Id', SOQL::object('Contact')->select('Account.Id'))->toSOQL();
```

- Ordering &amp; Limit

```
SOQL::object('Account')->select('Id')->orderBy('Id')->toSOQL(); // default order DESC
SOQL::object('Account')->select('Id')->orderBy('Name', 'ACS')->toSOQL();
SOQL::object('Account')->select('Id')->limit(1)->toSOQL();
```

ORM Usage
=========

[](#orm-usage)

Query Builder is good when you want full control over query, but it becomes cumbersome with a query where you need to select all the fields of an object or want to load child pr parent object rows. This package also provide object-relational-mapper (ORM) support that makes it easy and enjoyable to interact with soql.

### Generate Object Classes

[](#generate-object-classes)

To get started, lets create an Object class which by default lives in `app/Objects` directory and extend the `AhmadWaleed\Soquel\Object\BaseObject` class, but you can change the default directory in the configuration file. You may use the `make:object` artisan command to generate a new object class:

```
php artisan make:object Account
```

The above command will generate following class:

```
