23 lines
593 B
PHP
Executable File
23 lines
593 B
PHP
Executable File
<?php
|
|
|
|
namespace App\FormModel\admin\articles\trait;
|
|
|
|
use App\Model\AppArticle;
|
|
|
|
trait ModifyForUpdate
|
|
{
|
|
protected array $canUpdateFields = ['title', 'cover', 'images', 'brand', 'location'];
|
|
|
|
public function update()
|
|
{
|
|
$query = AppArticle::where(['aid' => $this->attributes['aid']])->first();
|
|
foreach ($this->canUpdateFields as $field) {
|
|
$val = $this->attributes[$field] ?? null;
|
|
if ($val !== null) {
|
|
$query->{$field} = $this->attributes[$field];
|
|
}
|
|
}
|
|
|
|
$query->save();
|
|
}
|
|
} |