first commit
This commit is contained in:
51
app/Models/Log.php
Normal file
51
app/Models/Log.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Schema;
|
||||
|
||||
class Log extends Model
|
||||
{
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $table;
|
||||
|
||||
protected $casts = [
|
||||
'in_source' => 'array',
|
||||
'out_source' => 'array',
|
||||
];
|
||||
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
parent::__construct($attributes);
|
||||
if (!$this->table) {
|
||||
$this->table = 'api_log_' . date('Ym');
|
||||
}
|
||||
|
||||
if (!Schema::hasTable($this->table)) {
|
||||
Schema::create($this->table, function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('path', 255);
|
||||
$table->string('method', 15);
|
||||
$table->text('in_source');
|
||||
$table->string('type', 20);
|
||||
$table->text('out_source')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function setTable($table)
|
||||
{
|
||||
if (Schema::hasTable($table)) {
|
||||
$this->table = $table;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user