26 lines
508 B
PHP
26 lines
508 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
|
||
|
|
abstract class Model
|
||
|
|
{
|
||
|
|
public function __construct(array $data = [])
|
||
|
|
{
|
||
|
|
foreach ($data as $k => $v) {
|
||
|
|
$this->__set($k, $v);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function __set(string $key, $value)
|
||
|
|
{
|
||
|
|
$setter = 'set' . Str::studly($key);
|
||
|
|
if (method_exists($this, $setter)) {
|
||
|
|
$this->$setter($value);
|
||
|
|
} elseif (property_exists($this, $key)) {
|
||
|
|
$this->$key = $value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|