New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

nowendwell/laravel-archivable

A trait to make an Eloquent model archivable
1,107 3
Install
composer require nowendwell/laravel-archivable
Latest Version:v1.0.1
PHP:^7.1
Laravel:5
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

pawelmysior/laravel-publishable

Toggle the published state of your Eloquent models easily

19,442 22
koodoo/laravel-trait-uuid

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

16,731 0
koodoo/laravel-trait-updatedby

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

16,642 1
greabock/tentacles

Da epic tentacles for Eloquent

34,559 36
p-andrey/tentacles

Da epic tentacles for Eloquent

13,852 1

Version History

Version Released PHP Laravel License
v1.0.1 ^7.1 5.7.* MIT
v1.0 ^7.1 5.8.* MIT