first commit
This commit is contained in:
23
app/FormModel/admin/articles/trait/ModifyForUpdate.php
Executable file
23
app/FormModel/admin/articles/trait/ModifyForUpdate.php
Executable file
@ -0,0 +1,23 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user