1234567891011121314151617181920212223242526272829303132 |
- <?php
- namespace App\model;
- trait TableSuffix
- {
- private static $suffix;
- public static function suffix($suffix)
- {
- static::$suffix = $suffix;
- }
- public function __construct(array $attributes = [])
- {
- $this->table .= static::$suffix;
- parent::__construct($attributes);
- }
- public static function model(int $month = 0)
- {
- $suffix = '';
- if ($month == 0) {
- $suffix = date('Ym');
- } else {
- $suffix = date('Ym', strtotime("last day of {$month} month"));
- }
- self::suffix($suffix);
- $model = new self;
- return $model;
- }
- }
|