HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot//www.zqgwfu.top/system/models/base.php
<?php
/**
 * base.php
 *
 * @copyright 2020 opencart.cn - All Rights Reserved
 * @link https://www.guangdawangluo.com
 * @author stiffer.chen <chenlin@opencart.cn>
 * @created 2020-06-2020/6/29 14:39
 * @modified 2020-06-2020/6/29 14:39
 */

namespace Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class Base extends Model
{
    public $timestamps = false;
    protected $modelName = '';

    public function __construct(array $attributes = [])
    {
        if (!$this->table) {
            $this->setTable($this->getCurrentClassName());
        }

        if ($this->primaryKey == 'id') {
            $this->setKeyName($this->getPrimaryName());
        }
        $this->modelName = str_replace('\\', '', Str::snake(static::class));
        parent::__construct($attributes);
    }

    public function getCurrentClassName()
    {
        return Str::snake(class_basename($this));
    }

    public function getPrimaryName()
    {
        return $this->getTable() . '_id';
    }

    public function getForeignKey()
    {
        return Str::snake(class_basename($this)) . '_id';
    }

    public function primaryValue()
    {
        return $this->{$this->getPrimaryName()};
    }

    public function getAllFields()
    {
        return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
    }

    public static function boot()
    {
        parent::boot();
        self::creating(function ($row) {
            $table = $row->getTable();
            if (\Schema::hasColumn($table, 'created_at')) {
                $row->created_at = Carbon::now()->toDateTimeString();
            }
            if (\Schema::hasColumn($table, 'date_added')) {
                $row->date_added = Carbon::now()->toDateTimeString();
            }

            if (\Schema::hasColumn($table, 'updated_at')) {
                $row->updated_at = Carbon::now()->toDateTimeString();
            }
            if (\Schema::hasColumn($table, 'date_modified')) {
                $row->date_modified = Carbon::now()->toDateTimeString();
            }
        });

        self::saving(function ($row) {
            $table = $row->getTable();
            if (\Schema::hasColumn($table, 'updated_at')) {
                $row->updated_at = Carbon::now()->toDateTimeString();
            }
            if (\Schema::hasColumn($table, 'date_modified')) {
                $row->date_modified = Carbon::now()->toDateTimeString();
            }
        });
    }
}