PHP code example of rob-lester-jr04 / laravel-sendle

1. Go to this page and download the library: Download rob-lester-jr04/laravel-sendle 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/ */

    

rob-lester-jr04 / laravel-sendle example snippets




use Sendle\Models\Order;

$order = new Order([
	'receiver' => [
		'contact' => [
			'name' => 'John Smith',
			'email' => '[email protected]',
		],
		'address' => [
			'address_line1' => '123 Main Street',
			'suburb' => 'New York',
			'postcode' => '10010',
			'state_name' => 'NY',
			'country' => 'US'
		],
		'instructions' => 'Leave it on the step',
	],
	'description' => 'test package',
	'product_code' => 'STANDARD-PICKUP',
	'weight' => [
		'value' => 14,
		'units' => 'oz',
	]
]);

$order->create();

// OR....

Order::create([
	...
]);




use Sendle\Models\Order;

Order::find('####');




use Sendle\Models\Product;
use Sendle\Models\Entity;

$receiver = new Entity([
	'contact' => [
		'name' => 'John Smith',
		'email' => '[email protected]',
	],
	'address' => [
		'address_line1' => '123 Main Street',
		'suburb' => 'New York',
		'postcode' => '10010',
		'state_name' => 'NY',
		'country' => 'US'
	],
	'instructions' => 'Leave it on the step',
]);

$weight = 26.0;

$products = Product::get($weight, $receiver);




namespace App\Models;

use Sendle\Traits\SendsPackages;

class User extends Model
{
	use SendsPackages;
	
	protected $sendleOrderCreate = [
		// Map your users address fields to sendle. sendle=>model
		'address_line1' => 'street_address',
		'suburb' => 'city',
		'state_name' => 'state',
	];
	
	//...
}

//.........//

$user = User::find(4);

$user->sendleOrderCreate('grandmas china', 36.0);

//.........//

$reciever = new Entity([
	'contact' => [ /** */],
	'address' => [
		/**  */
	],
]);

$user->sendleOrderCreate('grandmas china', 42, $receiver);