connection = 'redis'; //Import variables from the calling function $this->ledger = $ledger; $this->observerId = $observerId; } /** * Execute the job. * * @return void */ public function handle() { $lookup = new LookupHelper; $mHelper = new MoonCalc; //Get some of the basic information we need to work with $charName = $lookup->CharacterIdToName($this->ledger->character_id); //Get the type name from the ledger ore $typeName = $lookup->ItemIdToName($this->ledger->type_id); //Get the price from the helper function $price = $mHelper->CalculateOrePrice($this->ledger->type_id); //Calculate the total price based on the amount $amount = $price * $this->ledger->quantity; $found = Ledger::where([ 'character_id' => $this->ledger->character_id, 'observer_id' => $this->observerId, 'type_id' => $this->ledger->type_id, 'last_updated' => $this->ledger->last_updated, ])->count(); if($found > 0) { Ledger::where([ 'character_id' => $this->ledger->character_id, 'character_name' => $charName, 'observer_id' => $this->observerId, 'type_id' => $this->ledger->type_id, 'quantity' => $this->ledger->quantity, 'last_updated' => $this->ledger->last_updated, ])->update([ 'character_id' => $this->ledger->character_id, 'character_name' => $charName, 'observer_id' => $this->observerId, 'last_updated' => $this->ledger->last_updated, 'type_id' => $this->ledger->type_id, 'ore_name' => $typeName, 'quantity' => $this->ledger->quantity, 'amount' => $amount, ]); } else { $ledg = new Ledger; $ledg->character_id = $this->ledger->character_id; $ledg->character_name = $charName; $ledg->observer_id = $this->observerId; $ledg->last_updated = $this->ledger->last_updated; $ledg->type_id = $this->ledger->type_id; $ledg->ore_name = $typeName; $ledg->quantity = $this->ledger->quantity; $ledg->amount = $amount; $ledg->save(); } } }