first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

37
common/Votes/VoteController.php Executable file
View File

@@ -0,0 +1,37 @@
<?php
namespace Common\Votes;
use Common\Core\BaseController;
class VoteController extends BaseController
{
public function store()
{
$data = $this->validate(request(), [
'vote_type' => 'required|in:upvote,downvote',
'model_type' => 'required|string',
'model_id' => 'required|integer',
]);
$namespace = modelTypeToNamespace($data['model_type']);
$model = app($namespace)::findOrFail($data['model_id']);
$this->authorize('vote', $model);
$model = app(StoreVote::class)->execute(
$model,
$data['vote_type'],
getIp(),
);
$model->unsetRelation('votes');
$model->load([
'votes' => fn($builder) => $builder->withCurrentUserVotes(),
]);
$model->current_vote = $model->votes->first()?->vote_type;
$model->unsetRelation('votes');
return $this->success(['model' => $model]);
}
}