Category: Laravel, Laravel, PHP, PHP, javascript, javascript

I recently saw a tweet by https://twitter.com/Philo01 which states the slick use of a recently added Prunable trait in Laravel 8.x Essentially, from the version https://github.com/laravel/framework/releases/tag/v8.50.0, Laravel comes with a Prunable trait, which is when added to the models, allows to remove obsolete model records.

For this, all you need is to add the Illuminate\Database\Eloquent\Prunable trait to the model that you want to make prunable. Next, you’ll need to implement the prunable method where you need to write the condition that determines which records to prune.

This will allow Laravel to scan and detect all the models that have the Prunable trait under the app/models folder and prune the model records accordingly.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners