♻️ Move validation to Input class
This commit is contained in:
parent
b1f1f77b17
commit
3246004e58
5 changed files with 79 additions and 37 deletions
25
app/Models/Model.php
Normal file
25
app/Models/Model.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue