По работе у меня есть следующее:
Код: Выделить всё
public function __construct($dados, WgClient $model)
{
$this->dados = $dados;
$this->model = $model;
}
public function handle()
{
try {
$dataWG = [
'tipo' => 'interface',
'data' => $this->data
];
$response = Http::post('http://my.api.ip.address:port/login', [
'username' => '*',
'password' => '*',
]);
if (!isset($response->json()['access_token']))
throw new Exception("Erro na autenticação");
$token = $response->json()['access_token'];
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . $token,
])->post('http://my.api.ip.address:port/criar', $dataWG);
$response = json_decode($response, true);
$this->model->name = $response['name'];
$this->model->network = $response['network'];
$this->model->public_key = $response['public_key'];
$this->model->private_key = $response['private_key'];
$this->model->port = $response['port'];
$this->model->company = 13;
$this->model->save();
} catch (\Throwable $th) {
throw $th;
}
}
Код: Выделить всё
$data = $request->all();
$model = new WgClient;
CreateWgInterfaceJob::dispatch($data, $model);
Я попробовал оба ответа здесь и здесь, но они не сработали, и я действительно не понимаю, почему, я также пробовал с SerializesModels и без него, и я получаю тот же результат, все работает, но в базу данных ничего не поступает, и ошибок не видно, я знаю, что что-то упускаю, поэтому буду очень признателен за помощь и объяснения.
Подробнее здесь: https://stackoverflow.com/questions/784 ... -on-my-job