alejandrotrevi/laravel-ankal 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alejandrotrevi/laravel-ankal

Composer 安装命令:

composer require alejandrotrevi/laravel-ankal

包简介

Super simple statuses for your Laravel Models

README 文档

README

Latest Stable Version Total Downloads GitHub Actions

Sometimes you only need a simple way to manage statuses.

Installation

You can install the package via composer:

composer require alejandrotrevi/laravel-ankal

Optionally, you can publish the migration included with the library. The included migration is a good place to add the necessary columns to your tables or perhaps remove some columns from existing tables.

php artisan vendor:publish --provider="Alejandrotrevi\LaravelAnkal\LaravelAnkalServiceProvider" --tag="migrations"

Usage

Add the HasStatuses trait to a model.

use Alejandrotrevi\LaravelAnkal\HasStatuses;

class MyModel extends Model
{
    use HasStatuses;
}

Add the necessary migrations to each of the tables on which you will use the statuses.

Schema::create('my_table', function (Blueprint $table) {
    $table->statusColumns();
});

behind the scenes this basically adds 3 columns: status, reason and status_updated_at.

Optionally you can set a default status for that table, you simply pass an additional argument to the statusColumns() table modifier this additional argument is the default status the status column will have when you create a new model.

Schema::create('my_table', function (Blueprint $table) {
    $table->statusColumns('my_default_status');
});

Set a status

You can set a new status like this:

$model->setStatus('status');

You can also provide a reason for the status modification.

$model->setStatus('status', 'why this status changed?');

Since the status exist on the same table you simply call the status as another property on your model.

$model->status;
$model->reason;
$model->status_updated_at;

Scopes

You have 2 scopes available for your models currentStatus and exceptStatus.

// All models with status "status"
Model::currentStatus('status');

// All models with status "status" or "other-status"
Model::currentStatus('status', 'other-status');
Model::currentStatus(['status', 'other-status']);

Without a given status:

// All models except those with the "my-status" status
Model::exceptStatus('my-status');

// All models except those with the "my-status" or "other-status" statuses.
Model::exceptStatus('my-status', 'other-status');
Model::exceptStatus(['my-status', 'other-status']);

Testing

composer test

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 alex_tf_1992@live.com.mx instead of using the issue tracker.

Credits

This package is heavily inspired in the spatie/laravel-model-status package, this aims to be a simpler version of Spatie's solution, every credit should go to them 🤗

License

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

Why Ankal?

Ankal means "To be" in the Mayan language.

统计信息

  • 总下载量: 167
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固