mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
33 lines
951 B
PHP
33 lines
951 B
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Rewards\Services;
|
|
|
|
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
|
use App\Models\Reward;
|
|
use App\Models\User;
|
|
use App\Models\UserReward;
|
|
|
|
class CreatesUserReward extends AbstractUpdateRelationshipRecord
|
|
{
|
|
/**
|
|
* @param Reward $reward
|
|
* @param User $user
|
|
* @param int $voucherId
|
|
* @return \Illuminate\Database\Eloquent\Model|null
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
*/
|
|
public function execute(?Reward $reward, User $user, int $voucherId) {
|
|
if($reward){
|
|
$model = new UserReward();
|
|
$model->user_id = $user->id;
|
|
$model->voucher_id = $voucherId;
|
|
return $this->handler($reward->users(), $model);
|
|
}
|
|
else{
|
|
$model = new UserReward();
|
|
$model->voucher_id = $voucherId;
|
|
return $this->handler($user->rewards(), $model);
|
|
}
|
|
}
|
|
}
|