Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

caneara/tipsea

13 stars
3 code files
View caneara/tipsea on GitHub

app/Enums/NotificationType.php

Open in GitHub
enum NotificationType : int
{
case LIKE = 1;
case COMMENT = 2;
 
public function name() : string
{
return match ($this) {
static::LIKE => 'like',
static::COMMENT => 'comment',
};
}
}

app/Models/Notification.php

Open in GitHub
use App\Types\Model;
use App\Enums\NotificationType;
 
class Notification extends Model
{
//
protected $casts = [
'id' => 'integer',
'user_id' => 'integer',
'tip_id' => 'integer',
'type' => NotificationType::class,
'message' => 'string',
'read_at' => 'datetime',
];
//
}

app/Actions/Like/StoreAction.php

Open in GitHub
use App\Models\Tip;
use App\Models\Like;
use App\Models\User;
use App\Types\Action;
use App\Models\Notification;
use App\Enums\NotificationType;
use App\Actions\Notification\StoreAction as StoreNotificationAction;
 
class StoreAction extends Action
{
public static function execute(User $user, Tip $tip) : Like
{
$payload = [
'tip_id' => $tip->id,
];
 
if (static::notify($user, $tip)) {
StoreNotificationAction::execute($tip->user, $user, $tip, NotificationType::LIKE);
}
 
return attempt(fn() => $user->likes()->create($payload));
}
 
protected static function notify(User $user, Tip $tip) : bool
{
return Notification::query()
->where('tip_id', $tip->id)
->where('student_id', $user->id)
->doesntExist();
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.