Repository navigation
|
It would be great if I was able to prune old database notifications without extending notifications with custom model. What do you think ? |
Answered by
yilanboy
Dec 22, 2021
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. |
0 replies
Answer selected by
smknstd
|
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 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I create a
Notificationmodel and use Pruning Models to clean the stale notification records.then add this prune task in
Console/Kernel.phpIt's worked fo…