app()->post('/createThread', function () {
$user = auth()->user()->get();
if (!$user) {
return response()->render('login',[
'status' => 'error',
'message' => 'Debe iniciar sesión',
'data' => auth()->errors(),
]);
}
$userData = request()->get(['title', 'message', 'topic_id']);
$db = db();
$db->insert('threads')->params([
'title' => $userData['title'],
'user_id' => auth()->id(),
'topic_id' => $userData['topic_id']
])->execute();
$thread_id = $db->lastInsertId();
$db->insert('comments')->params([
'message'=>$userData['message'],
'user_id' => auth()->id(),
'thread_id'=>$thread_id
])->execute();
return response()->redirect('/thread/{$thread_id}');
});
However, I'm getting the aforementioned error 5 and I tried with the transaction function callback but I get another error "no active transaction". The documentation is not super exhaustive and no resource is helpful. Thanks.