Skip to content

Instantly share code, notes, and snippets.

@vojtasvoboda
Created January 4, 2016 10:35
Show Gist options
  • Save vojtasvoboda/46f141c5c7e38c7784fa to your computer and use it in GitHub Desktop.
Save vojtasvoboda/46f141c5c7e38c7784fa to your computer and use it in GitHub Desktop.
Deferred binding in OctoberCMS
// INIT: session key as transfer unique identifier
$sessionKey = 'abcdefghijklmnopqrstuvwxyz';
// PART ONE: receiving files
// receive first file
$file = new System\Models\File();
$file->fromFile(base_path() . '/storage/app/media/users/12905.jpg');
$file->save();
// receive second file
$file2 = new System\Models\File();
$file2->fromFile(base_path() . '/storage/app/media/users/16907.jpg');
$file2->save();
// add files to demand
$demand = new VojtaSvoboda\Demands\Models\Demand;
$demand->images()->add($file, $sessionKey);
$demand->images()->add($file2, $sessionKey);
dump($demand);
// PART TWO: receiving demand data
// receive data
$demand2 = new VojtaSvoboda\Demands\Models\Demand;
$data = [
'amount' => '150000',
'maturity' => '12',
'email' => '[email protected]',
'phone' => '777111222',
'property_type' => 'Byt',
'property_town' => 'Praha',
'property_zip' => '10000'
];
$demand2->fill($data);
// save demand with files received in part one (were saved in deferred_bindings DB table)
$demand2->save(null, $sessionKey);
dump($demand2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment