This is a Laravel Package for adding stamp behaviors into laravel models. This package supports Laravel 5.2+
.
Via Composer
$ composer require shetabit/stampable
In your migration you must add timestamp
field per each stamp.
// In migration, you must add published_at field like the below if you want to use it as a stamp.
$table->timestamp('published_at')->nullable();
In your eloquent model add use HasStamps
trait like the below.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Shetabit\Stampable\Contracts\Stampable;
use Shetabit\Stampable\Traits\HasStamps;
class Category extends Model implements Stampable
{
use HasStamps;
//
}
you can define stamps using protected stamps
attribute the model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Shetabit\Stampable\Contracts\Stampable;
use Shetabit\Stampable\Traits\HasStamps;
class Category extends Model implements Stampable
{
use HasStamps;
protected $stamps = [
'published' => 'published_at',
];
//
}
stamps must be in ['stampName' => 'databaseFieldName']
format.
Model creates methods and local scopes for each stamp dynamically.
According to the latest example, now we have the below methods for each Category
instance.
<?php
/**
* notice that be have all of this methods and scopes for each stamps.
* the name of methods will be similar to the stamp's name.
**/
// methods:
$category->markAsPublished(); // press published stamp on this category!
$category->markAsUnpublished(); // Remove stamp mark from this category.
$category->isPublished(); // Determines if this category is published.
$category->isnUnpublished(); // Determinces if this category is Unpublished.
// scopes: you can use scopes to filter your data using stamp status.
Category::published()->get(); // retrieve published datas
Category::unpublished()->get(); // retrieve unpublished datas
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.