PHP code example of maize-tech / laravel-model-expires
1. Go to this page and download the library: Download maize-tech/laravel-model-expires library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
maize-tech / laravel-model-expires example snippets
return [
/*
|--------------------------------------------------------------------------
| Expiration model
|--------------------------------------------------------------------------
|
| Here you may specify the fully qualified class name of the expiration model.
|
*/
'expiration_model' => Maize\ModelExpires\Models\Expiration::class,
'model' => [
/*
|--------------------------------------------------------------------------
| Expires after days
|--------------------------------------------------------------------------
|
| Here you may specify the default amount of days after which a model
| should expire.
| If null, all newly created models won't have a default expiration date.
|
*/
'expires_after_days' => null,
/*
|--------------------------------------------------------------------------
| Deletes after days
|--------------------------------------------------------------------------
|
| Here you may specify the default amount of days after which a model
| should be deleted.
| If null, all newly created models won't have a default deletion date.
|
*/
'deletes_after_days' => null,
],
'expiring_notification' => [
/*
|--------------------------------------------------------------------------
| Enable expiring notification
|--------------------------------------------------------------------------
|
| Here you may specify whether you want to enable model expiring
| notifications or not.
|
*/
'enabled' => true,
/*
|--------------------------------------------------------------------------
| Notification class
|--------------------------------------------------------------------------
|
| Here you may specify the fully qualified class name of the default notification.
| If null, no notifications will be sent.
|
*/
'notification' => Maize\ModelExpires\Notifications\ModelExpiringNotification::class,
/*
|--------------------------------------------------------------------------
| Notifiable emails
|--------------------------------------------------------------------------
|
| Here you may specify the default list of notifiable email addresses.
|
*/
'notifiables' => [
//
],
],
];
bash
php artisan model-expires:install
php
$user = User::create([])->setExpiresAt(
expiresAt: now()->addDays(5),
deletesAt: now()->addDays(10),
);
$user->isExpired(); // returns false
$user->getDaysLeftToExpiration(); // returns 5
$user->getDaysLeftToDeletion(); // returns 10
$user = User::create([])->setExpiresAt(
expiresAt: now()->subDay()
);
$user->isExpired(); // returns true
$user->getDaysLeftToExpiration(); // returns 0, as the model is already expired
$user->getDaysLeftToDeletion(); // returns null, as model does not have a deletion date
php
$user = User::create([]); // user does not have an expiration date
$expiredUser = User::create([])->setExpiresAt(
expiresAt: now()->subDay(),
); // user is already expired
User::withoutExpired()->count(); // returns 1, which is the $user model
User::withoutExpired()->get(); // returns the $user model
php
$user = User::create([]); // user does not have an expiration date
$expiredUser = User::create([])->setExpiresAt(
expiresAt: now()->subDay(),
); // user is already expired
User::onlyExpired()->count() // returns 1, which is the $expiredUser model
User::onlyExpired()->get(); // returns the $expiredUser model