PHP code example of ahmedwaleed / soquel
1. Go to this page and download the library: Download ahmedwaleed/soquel 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/ */
ahmedwaleed / soquel example snippets
php artisan vendor:publish --provider="Omniphx\Forrest\Providers\Laravel\ForrestServiceProvider::class"
'credentials' => [
// Required:
'consumerKey' => env('SF_CONSUMER_KEY'),
'consumerSecret' => env('SF_CONSUMER_SECRET'),
'callbackURI' => env('SF_CALLBACK_URI'),
'loginURL' => env('SF_LOGIN_URL'),
// Only
'storage' => [
'type' => 'cache', // Options id collisions
'expire_in' => 60, // number of minutes to expire cache/session
'store_forever' => false, // never expire cache/session
]
use AhmadWaleed\Soquel\SOQL;
echo SOQL::object('Account')->select('Id', 'Name')->toSOQL();
// Output: SELECT Id, Name FROM Account
SOQL::object('Account')->select('Id', 'Name')->where('Id', '=', 's3dty')->toSOQL();
SOQL::object('Account')->select('Id', 'Name')->where('Name', 'Like', '%john%')->toSOQL();
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();
SOQL::object('Account')->select('Id', 'Name')->selectSub(SOQL::object('Contact')->select('Id', 'Name'))->toSOQL();
SOQL::object('Account')->select('Id')->whereIn('Id', SOQL::object('Contact')->select('Account.Id'))->toSOQL();
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();
namespace App\Objects;
use AhmadWaleed\Soquel\Object\BaseObject;
class Account extends BaseObject
{
}
namespace App\Objects;
use AhmadWaleed\Soquel\Object\BaseObject;
class Job extends BaseObject
{
protected string $sobject = 'Job__c';
}
public array $fields = [
'Name',
'Email',
];
protected array $readOnly = ['Name'];
use App\Objects\Account;
foreach(Account::new()->query()->get() as $account) {
echo $account->name;
}
$accounts = Account::new()
->query()
->where('name', 'LIKE', '%john%')
->limit(10)
->get();
$accounts = Account::new()->query()->whereNotNull('Email')->get();
$accounts = $accounts->reject(fn (Account $account) => $account->isActive);
$account->contacts()->where('Name', 'LIKE', '%john%');
namespace AhmadWaleed\Soquel\Tests\Objects;
use AhmadWaleed\Soquel\Object\BaseObject;
use AhmadWaleed\Soquel\Object\ParentRelation;
class Contact extends BaseObject
{
public Account $account;
public function account(): ParentRelation
{
return $this->parentRelation(Account::class);
}
}
$account = Contact::new()->query()->with('account')->find('id')->account;
return $this->parentRelation(Job::class, 'Job__c');
return $this->parentRelation(Job::class, 'Job__c', 'jobs');
namespace AhmadWaleed\Soquel\Tests\Objects;
use AhmadWaleed\Soquel\Object\BaseObject;
use AhmadWaleed\Soquel\Object\ChildRelation;
use Illuminate\Support\Collection;
class Account extends BaseObject
{
public Collection $contacts;
public function contacts(): ChildRelation
{
return $this->childRelation(Contact::class);
}
}
$contacts = Account::new()->query()->with('contacts')->find('id')->contacts;
return $this->childRelation(Attachment::class, 'Attachment__c');
return $this->childRelation(Attachment::class, 'Attachment__c', 'attachments');
$contact = new Contact();
$contact->LastName = 'doe';
$contact->Email = '[email protected] ';
$contact->save();
// OR
$contact = Contact::create(['LastName' => 'doe', 'Email', '[email protected] ']);
$contacts = collect([
new Contact(['Email' => '[email protected] ']),
new Contact(['Email' => '[email protected] '])
]);
Contact::saveMany($contacts);
// OR
$contacts = collect([
['Email' => '[email protected] '],
['Email' => '[email protected] ']
]);
Contact::saveMany($contacts);
$contact = new Contact();
$contact->LastName = 'michael';
$contact->save();
// OR
$contact = $contact->update(['LastName' => 'michael', 'Email', '[email protected] ']);
bash
php artisan make:object Account