Skip to content

Commit 40eb501

Browse files
author
=
committed
Update readme usage block
1 parent bccaa51 commit 40eb501

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<a href="https://packagist.org/packages/joelbutcher/laravel-archivable"><img src="https://img.shields.io/packagist/l/joelbutcher/laravel-archivable" alt="License"></a>
99
</p>
1010

11-
A simple package for making Laravel Eloquent models 'archivable'. This package registers three macros. One for Laravel's `\Illuminate\Database\Schema\Blueprint` class for writing migrations with the `archivedAt` directive. Two more macros are registered for Laravel's `\Illuminate\Database\Query\Builder` class, allowing calls to `archive` and `unArchive` between Eloquent relationships.
11+
A simple package for making Laravel Eloquent models 'archivable'. This package allows for the easy archiving of models by creating various macros to be used within method chaining.
1212

1313
## Installation
1414

@@ -20,20 +20,37 @@ composer require joelbutcher/laravel-archivable
2020

2121
## Usage
2222

23-
Typically, the trait works similarly to Laravels `SoftDeletes` trait. Therefore, any model that has an `archived_at` column in it's table schema can utilise the `\LaravelArchivable\Archivable` trait.
23+
#### Migrations
24+
25+
The `Archivable` trait works similarly to Laravel's `SoftDeletes` trait. To ensure proper usage of the trait. This package also ships with a helpful macro for Laravel's `\Illuminate\Database\Schema\Blueprint`. To get started, simply add the `archivedAt` macro to your migration, like so:
26+
27+
```php
28+
Schema::create('posts', function (Blueprint $table) {
29+
$table->id();
30+
$table->unsignedBigInteger('user_id');
31+
$table->string('title');
32+
$table->timestamps();
33+
$table->archivedAt(); // Macro
34+
});
35+
```
36+
37+
#### Eloquent
38+
You can now, safely, include the `Archivable` tait in your eloquent model:
2439

2540
``` php
2641
namespace App\Models;
2742

2843
use \Illuminate\Database\Eloquent\Model;
2944

30-
class ArchivablePost extends Model {
45+
class Post extends Model {
3146

3247
use Archivable;
3348
...
3449
}
3550
```
3651

52+
#### Extensions
53+
3754
The extensions shipped with this trait include; `archive`, `unArchive`, `WithArchived`, `withoutArchived`, `onlyArchived` and can be used accordingly:
3855

3956
```php

0 commit comments

Comments
 (0)