### Install Laravel Archivable via Composer Source: https://github.com/joelbutcher/laravel-archivable/blob/1.x/README.md This command installs the Laravel Archivable package using Composer, the dependency manager for PHP. Ensure Composer is installed and accessible in your terminal. ```bash composer require joelbutcher/laravel-archivable ``` -------------------------------- ### Eloquent Model Archiving Operations Source: https://github.com/joelbutcher/laravel-archivable/blob/1.x/README.md These PHP examples illustrate how to use the extensions provided by the `Archivable` trait on Eloquent models. They cover archiving, unarchiving, checking the archived status, and querying models that include or only show archived records. ```php $user = User::first(); $user->archive(); $user->unArchive(); // Check Archive status $user->isArchived(); $usersWithArchived = User::query()->withArchived(); $onlyArchivedUsers = User::query()->onlyArchived(); ``` -------------------------------- ### Add ArchivedAt Macro to Laravel Migration Source: https://github.com/joelbutcher/laravel-archivable/blob/1.x/README.md This PHP snippet demonstrates how to add an `archivedAt` column to a Laravel migration using the package's schema builder macro. This column will store the timestamp when a model is archived. The rollback example shows how to drop this column. ```php Schema::create('posts', function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('user_id'); $table->string('title'); $table->timestamps(); $table->archivedAt(); // Macro }); ``` ```php Schema::create('posts', function (Blueprint $table) { $table->dropArchivedAt(); }); ``` -------------------------------- ### Use Archivable Trait in Eloquent Model Source: https://github.com/joelbutcher/laravel-archivable/blob/1.x/README.md This PHP code shows how to incorporate the `Archivable` trait into a Laravel Eloquent model. By using this trait, the model gains access to all the archiving functionalities provided by the package. ```php namespace App\Models; use \Illuminate\Database\Eloquent\Model; use \LaravelArchivable\Archivable; class Post extends Model { use Archivable; ... } ``` -------------------------------- ### Enable Archived Model Binding in Laravel Routes Source: https://github.com/joelbutcher/laravel-archivable/blob/1.x/README.md This PHP code snippet shows how to enable implicit model binding for archived models in Laravel routes. By chaining the `withArchived()` method onto the route definition, the route will be able to resolve archived models. ```php use App\Models\User; Route::get('/users/{user}', function (User $user) { return $user->email; })->withArchived(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.