Skip to content

Instantly share code, notes, and snippets.

@zhanang19
Created February 5, 2020 04:46
Show Gist options
  • Save zhanang19/2cd8fa967407388f267afcc831fb3a61 to your computer and use it in GitHub Desktop.
Save zhanang19/2cd8fa967407388f267afcc831fb3a61 to your computer and use it in GitHub Desktop.
<?php
namespace Gazeboin\Event\Domain\Services;
use Gazeboin\Event\Domain\Entities\EventEntity;
use Gazeboin\Event\Domain\Entities\EventAttemptEntity;
class AttemptEventService
{
public function attempt($eventId, $data)
{
EventEntity::findOrFail($eventId);
$attempt = new EventAttemptEntity;
$attempt->user_id = $data->get('user_id');
$attempt->event_id = $id;
$isSuccess = $attempt->save();
$attempt->refresh();
if ($isSuccess) {
$message = 'Sucessfully attempt user to an event';
} else {
$message = 'Failed to attempt';
}
return collect([
'message' => $message,
'success' => $isSuccess,
'data' => $attempt ?? []
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment