| Kullanıcı Tipi | Günlük Limit | Açıklama |
|---|---|---|
| 🚫 Guest | Her şarkının 30 saniyesi | Fade-out ile bitiş, kayıt teşviki |
| 👤 Normal Üye | 5 tam şarkı | Her gece 00:00'da reset |
| ⭐ Premium/Deneme | Sınırsız | Tüm yetkiler |
// Users tablosuna SADECE 2 alan ekliyoruz: daily_songs_played INT DEFAULT 0 last_song_reset DATE NULL // Bu kadar! Basit ve temiz.
Schema::table('users', function (Blueprint $table) {
$table->integer('daily_songs_played')->default(0);
$table->date('last_song_reset')->nullable();
});
// Şarkı çalabilir mi?
public function canPlaySong(): bool
{
// Lazy reset
if ($this->last_song_reset < today()) {
$this->update([
'daily_songs_played' => 0,
'last_song_reset' => today()
]);
}
// Premium/Trial unlimited
if ($this->isPremium() || $this->isTrialActive()) {
return true;
}
// Normal üye: 5 şarkı limiti
return $this->daily_songs_played < 5;
}
// Şarkı dinlendi
public function incrementSongCount(): void
{
if (!$this->isPremium() && !$this->isTrialActive()) {
$this->increment('daily_songs_played');
}
}
// Şarkı çalmadan önce kontrol
public function stream($songId)
{
$user = auth()->user();
if (!$user->canPlaySong()) {
return response()->json([
'error' => 'daily_limit_exceeded',
'message' => 'Günlük 5 şarkı limitiniz doldu',
'played' => $user->daily_songs_played,
'limit' => 5
], 403);
}
// Stream URL'i dön
return response()->json([
'stream_url' => $song->getStreamUrl(),
'remaining' => 5 - $user->daily_songs_played
]);
}
// Şarkı bitince
public function onSongEnd($songId)
{
auth()->user()->incrementSongCount();
return response()->json(['success' => true]);
}
// Şarkı çalmadan önce
async function playSong(songId) {
const response = await fetch(`/api/muzibu/songs/${songId}/stream`);
if (response.status === 403) {
// Limit doldu modal göster
showLimitModal();
return;
}
const data = await response.json();
howler.play(data.stream_url);
// Şarkı bitince API call
howler.on('end', () => {
fetch(`/api/muzibu/songs/${songId}/track`, { method: 'POST' });
});
}
- Migration: 2 alan
- User Model: 2 method
- API: 2 endpoint
- Frontend: 10 satır kod
Basit, temiz, performanslı! 🚀