PHP code example of doloan09 / laravel-model-expires

1. Go to this page and download the library: Download doloan09/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/ */

    

doloan09 / laravel-model-expires example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mvdnbrk\EloquentExpirable\Expirable;

class Subscription extends Model
{
    use Expirable;
}

class CreateSubscriptionsTable extends Migration
{
    public function up(): void
    {
        Schema::create('subscriptions', function (Blueprint $table) {
            $table->expires();
        });
    }

    public function down(): void
    {
        Schema::dropExpires();
    }
}


class Subscription extends Model
{
    use Expirable;

    const EXPIRES_AT = 'ends_at';
}

$table->expires('ends_at');
$table->dropExpires('ends_at');

$subscription->expires_at = 600;

$subscription->expires_at = now()->addMinutes(10);

$subscription->expires_at = 0;
$subscription->expires_at = -5;

$subscription->discardExpiration()->save();

if ($subscription->expired()) {
    //
}

if ($subscription->willExpire()) {
    //
}

$subscriptions = App\Models\Subscription::withoutExpired()->get();

$subscriptions = App\Models\Subscription::onlyExpired()->get();

$subscriptions = App\Models\Subscription::expiring()->get();

$subscriptions = App\Models\Subscription::notExpiring()->get();