mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-09-22 09:13:01 -04:00
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Subscription\Repositories;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\Subscription\Entities\PaymentCode;
|
|
use Modules\Subscription\Entities\PaymentCodeAddon;
|
|
|
|
class PaymentCodeRepository
|
|
{
|
|
|
|
public function all() {
|
|
return PaymentCode::with(['user','planPrice.plan','addons'])->withSum('addons', 'price')->orderBy('id')->get();
|
|
}
|
|
|
|
public function create($request) {
|
|
$data = $request->except('_token');
|
|
|
|
$total = 0;
|
|
$paymentCode = PaymentCode::create($data);
|
|
if($data['addons'] != null){
|
|
$paymentCode->addons()->createMany($data['addons']);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function update($request) {
|
|
$data = $request->except('_token');
|
|
|
|
$paymentCode = PaymentCode::find($data['id']);
|
|
if($paymentCode){
|
|
$paymentCode->update($data);
|
|
|
|
foreach ($data['addons'] as $key => $addon) {
|
|
$paymentCode->addons()->updateOrCreate(
|
|
[
|
|
'id' => $addon['id'] ?? null,
|
|
],
|
|
$addon
|
|
);
|
|
}
|
|
|
|
$addOnsId = collect($data['addons'])->pluck('id')->toArray();
|
|
$paymentCode->addons()->whereNotIn('id', $addOnsId)->delete();
|
|
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|