nowendwell/laravel-archivable

A trait to make an Eloquent model archivable
1,106 3
Install
composer require nowendwell/laravel-archivable
Latest Version:v1.0.1
PHP:^7.1
License:MIT
Last Updated:Apr 5, 2019
Links: GitHub  ·  Packagist
Maintainer: nowendwell

A trait to make Eloquent models archivable

Latest Version on Packagist Total Downloads

This package contains a trait to make Eloquent models archivable. This works in a similar way to the SoftDelete trait that Laravel ships with.

Once you have applied to the trait to a model you can do the following:

// to archive a User
$user = User::find(1);
$user->archive();

// to unarchive a User
$user = User::withArchived()->find(1);
$user->unarchive();

Installation

You can install the package via composer:

composer require nowendwell/laravel-archivable

Making a model archivable

To make model archivable add the Nowendwell\LaravelArchivable\Archivable trait to the model you wish to archive

use Illuminate\Database\Eloquent\Model;
use Nowendwell\LaravelArchivable\Archivable;

class User extends Model
{
    use Archivable;
}

Usage

This traits adds a Global Query Scope to exclude any models that have a value in the archived_at column.

Archiving

// to archive a User
$user = User::find(1);
$user->archive();

Unarchiving

// to unarchive a User
$user = User::withArchived()->find(1);
$user->unarchive();

Checking Archive Status

// to unarchive a User
$user = User::withArchived()->find(1);
var_dump( $user->archived() ); // bool true/false

Query Scopes

User::withArchived()->get(); // returns all users
User::withOutArchived()->get(); // returns users that are not archived, same results as User::all()
User::onlyArchived()->get() // returns only users that have a value in the archived_at column

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email nowendwell@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

Related Packages

koodoo/laravel-trait-uuid

A Laravel Eloquent Model trait for adding a UUID to Eloquent Models

16,602 0
mobilerocket/laravel-trait-updatedby

A Laravel Eloquent Model trait for adding User Id's to Eloquent Models

83 1
ironshark/laravel-extendable

Traits for Laravel to add and manage custom Eloquent model fields.

11,037 24
cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

745,698 1,126
sugar-agency/laravel-favorites

Implementation of a 'like' or 'favorite' or 'remember' feature. Supports for ses...

1,042 9