feat: 项目基础框架+配置+Kernel
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* hujinsuo01
|
||||
* 继承此类可以创建此model的触发器
|
||||
*
|
||||
*/
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BaseModel extends Model
|
||||
{
|
||||
public static function boot() {
|
||||
parent::boot();
|
||||
$myself = get_called_class();
|
||||
$hooks = array('before' => 'ing', 'after' => 'ed');
|
||||
$radicals = array('sav', 'validat', 'creat', 'updat', 'delet');
|
||||
foreach ($radicals as $rad) {
|
||||
foreach ($hooks as $hook => $event) {
|
||||
$method = $hook.ucfirst($rad).'e';
|
||||
if (method_exists($myself, $method)) {
|
||||
$eventMethod = $rad.$event;
|
||||
self::$eventMethod(function($model) use ($method){
|
||||
return $model->$method($model);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user