use transaction
This commit is contained in:
parent
969bc79cbc
commit
0587a0f1d4
@ -10,6 +10,7 @@ use App\Http\Resources\EjaculationResource;
|
|||||||
use App\Tag;
|
use App\Tag;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
class WebhookController extends Controller
|
class WebhookController extends Controller
|
||||||
@ -60,30 +61,34 @@ class WebhookController extends Controller
|
|||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ejaculation = Ejaculation::create([
|
$ejaculation = DB::transaction(function () use ($request, $inputs, $webhook, $ejaculatedDate) {
|
||||||
'user_id' => $webhook->user_id,
|
$ejaculation = Ejaculation::create([
|
||||||
'ejaculated_date' => $ejaculatedDate,
|
'user_id' => $webhook->user_id,
|
||||||
'note' => $inputs['note'] ?? '',
|
'ejaculated_date' => $ejaculatedDate,
|
||||||
'link' => $inputs['link'] ?? '',
|
'note' => $inputs['note'] ?? '',
|
||||||
'source' => Ejaculation::SOURCE_WEBHOOK,
|
'link' => $inputs['link'] ?? '',
|
||||||
'is_private' => $request->has('is_private') ?? false,
|
'source' => Ejaculation::SOURCE_WEBHOOK,
|
||||||
'is_too_sensitive' => $request->has('is_too_sensitive') ?? false,
|
'is_private' => $request->has('is_private') ?? false,
|
||||||
'checkin_webhook_id' => $webhook->id
|
'is_too_sensitive' => $request->has('is_too_sensitive') ?? false,
|
||||||
]);
|
'checkin_webhook_id' => $webhook->id
|
||||||
|
]);
|
||||||
|
|
||||||
$tagIds = [];
|
$tagIds = [];
|
||||||
if (!empty($inputs['tags'])) {
|
if (!empty($inputs['tags'])) {
|
||||||
foreach ($inputs['tags'] as $tag) {
|
foreach ($inputs['tags'] as $tag) {
|
||||||
$tag = trim($tag);
|
$tag = trim($tag);
|
||||||
if ($tag === '') {
|
if ($tag === '') {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag = Tag::firstOrCreate(['name' => $tag]);
|
||||||
|
$tagIds[] = $tag->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tag = Tag::firstOrCreate(['name' => $tag]);
|
|
||||||
$tagIds[] = $tag->id;
|
|
||||||
}
|
}
|
||||||
}
|
$ejaculation->tags()->sync($tagIds);
|
||||||
$ejaculation->tags()->sync($tagIds);
|
|
||||||
|
return $ejaculation;
|
||||||
|
});
|
||||||
|
|
||||||
if (!empty($ejaculation->link)) {
|
if (!empty($ejaculation->link)) {
|
||||||
event(new LinkDiscovered($ejaculation->link));
|
event(new LinkDiscovered($ejaculation->link));
|
||||||
|
Loading…
Reference in New Issue
Block a user