https://github.com/shetabit/stampable
a Laravel Package for adding stamp behaviors into laravel models.
https://github.com/shetabit/stampable
laravel stamp stampable
Last synced: 6 months ago
JSON representation
a Laravel Package for adding stamp behaviors into laravel models.
- Host: GitHub
- URL: https://github.com/shetabit/stampable
- Owner: shetabit
- License: mit
- Created: 2019-06-13T19:53:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-21T18:41:38.000Z (over 6 years ago)
- Last Synced: 2025-04-10T10:47:50.577Z (9 months ago)
- Topics: laravel, stamp, stampable
- Language: PHP
- Homepage:
- Size: 38.1 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README

# Laravel Stampable
[![Software License][ico-license]](LICENSE.md)
[![Latest Version on Packagist][ico-version]][link-packagist]
[](https://github.styleci.io/repos/191824596)
[](https://codeclimate.com/github/shetabit/stampable/maintainability)
[![Quality Score][ico-code-quality]][link-code-quality]
This is a Laravel Package for adding stamp behaviors into laravel models. This package supports `Laravel 5.2+`.
# List of contents
- [Install](#install)
- [How to use](#how-to-use)
- [Configure migration](#configure-migration)
- [Configure Model](#configure-model)
- [Define stamps](#define-stamps)
- [Working with stamps](#working-with-stamps)
- [Change log](#change-log)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#credits)
- [License](#license)
## Install
Via Composer
``` bash
$ composer require shetabit/stampable
```
# How to use
## Configure Migration
In your migration you must add `timestamp` field per each stamp.
```php
// 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();
```
## Configure Model
In your eloquent model add use `HasStamps` trait like the below.
```php
'published_at',
];
//
}
```
stamps must be in `['stampName' => 'databaseFieldName']` format.
## Working with stamps
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
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
```
## Change log
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.
## Security
If you discover any security related issues, please email khanzadimahdi@gmail.com instead of using the issue tracker.
## Credits
- [Mahdi khanzadi][link-author]
- [All Contributors][link-contributors]
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/shetabit/stampable.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/shetabit/stampable.svg?label=Code%20Quality&style=flat-square
[link-en]: README.md
[link-packagist]: https://packagist.org/packages/shetabit/stampable
[link-code-quality]: https://scrutinizer-ci.com/g/shetabit/stampable
[link-author]: https://github.com/khanzadimahdi
[link-contributors]: ../../contributors