-
It would be great if I was able to prune old database notifications without extending notifications with custom model. What do you think ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I create a <?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\MassPrunable;
class Notification extends Model
{
use HasFactory, MassPrunable;
public function prunable(): Builder
{
return static::whereNotNull('read_at')
->where('read_at', '<=', now()->subWeek());
}
} then add this prune task in protected function schedule(Schedule $schedule)
{
$schedule->command('model:prune')->daily();
} It's worked for me. |
Beta Was this translation helpful? Give feedback.
-
Thanks @YilanBoy, I just wrote a really simple blog post, I hope it can help someone someday: https://medium.com/code16/automatically-delete-read-database-notifications-in-laravel-59871ee3c98 |
Beta Was this translation helpful? Give feedback.
I create a
Notification
model and use Pruning Models to clean the stale notification records.then add this prune task in
Console/Kernel.php
It's worked fo…