定制 soroushrah/action 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

soroushrah/action

Composer 安装命令:

composer require soroushrah/action

包简介

Action and Event like Wordpress Hooks

README 文档

README

eventy logo


Hook in Laravel

About

Actions are pieces of code you want to execute at certain points in your code.

Installation

  1. Install using Composer
composer require soroushrah/action
  1. Add the service provider to the providers array in your config/app.php.
    Soroush\Action\ActionServiceProvider::class,
    Soroush\Action\ActionBladeServiceProvider::class,
  1. Add the facade in config/app.php
    'Action' => \Soroush\Action\Facades\Action::class,

Usage

Actions

Anywhere in your code you can create a new action like so:

\Action::action('my.hook', 'soroush');

The first parameter is the name of the hook And Everything You pass after is argument.

To listen to your hooks, you attach listeners. These are best added to your AppServiceProvider boot() method.

For example if you wanted to hook in to the above hook, you could do:

\Action::addAction('my.hook', function($what) {
    echo 'Hello '. $what;
}, 20, 1);

Again the first argument must be the name of the hook. second would be a callback. Third is Priority. Fourth is number of arguments would accepted.(default is 1)

Using in Blade

Adding the same action as the one in the action example above:

@action('my.hook', 'awesome')

Add Daynamic Relation Models

For add some relation on models are not in your module you should use HasDynamicRelation trait in your all project model :

class MyModel extends Model {
    use HasDynamicRelation;
}

Then add dynamic relation like example above on providers :

MyModel::addDynamicRelation('some_relation', function(MyModel $model) {
    return $model->hasMany(SomeRelatedModel::class);
});

Credits

  • Created by Soroush Rahmani

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-09-12