I'm trying to change some property values of my account object. I'm trying to set a value on domain and password
When I log my object before I send it over to my front end (using vue), the object seems to be modified to my needs, but when I console.log() it in the browser the property values are null.
I'm using Laravel excel to create the accounts. After an account is created I use events with listeners to send my account objects to my view with pusher.
How do I do this properly?
AccountsImport
class AccountsImport implements ToCollection, withHeadingRow
{
use Importable;
private $data;
public function __construct(array $data = [])
{
$this->data = $data;
}
public function collection(Collection $rows)
{
$rows->each(function ($row, $key) {
$account = Account::create(array_merge([
'name' => mb_convert_encoding($row['student'], "UTF-8", mb_detect_encoding($row['student'], "UTF-8, ISO-8859-1, ISO-8859-15", true)),
'email' => $row['school_e_mailadres'],
], $this->data));
event(new AccountCreation($account));
});
}
}
AccountCreation event gets fired and SetHostingAccount listener will run
public function handle(AccountCreation $event)
{
$generator = new ComputerPasswordGenerator();
$generator->setUppercase()->setLowercase()->setNumbers()->setSymbols(false)->setLength(20);
$password = $generator->generatePassword();
$domain = preg_replace('/\s+/', '.', mb_strtolower($event->account->name . ' mtantwerp.eu'));
$event->account->{"domain"} = $domain;
$event->account->{"password"} = $password;
\Log::debug($event->account);
return $event->account;
}
Vue
created() {
Echo.channel("account-channel").listen("AccountCreation", e => {
console.log(e.account);
this.accounts.unshift(e.account);
});
}
Log results
Example result of \Log::debug($event->account)
{"name":"John Doe","email":"john.doe@student.kdg.be","package":"KDG student","id":577,"domain":"john.doe.mtantwerp.eu","password":"r5RSEvQBYnTF7RkPtL8Y"}
Console.log(e.account) in view
Object
domain: null
email: "john.doe@student.kdg.be"
id: 703
name: "Doe John"
package: "KDG student"
password: null
status: "created"