first commit
This commit is contained in:
11
app/FormModel/admin/articles/ArticlesModel.php
Executable file
11
app/FormModel/admin/articles/ArticlesModel.php
Executable file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles;
|
||||
|
||||
class ArticlesModel
|
||||
{
|
||||
public function edit()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
15
app/FormModel/admin/articles/BaseModify.php
Executable file
15
app/FormModel/admin/articles/BaseModify.php
Executable file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles;
|
||||
|
||||
class BaseModify
|
||||
{
|
||||
|
||||
protected array $attributes = [];
|
||||
|
||||
public function setAttributes(array $modifyData): static
|
||||
{
|
||||
$this->attributes = $modifyData;
|
||||
return $this;
|
||||
}
|
||||
}
|
11
app/FormModel/admin/articles/ModifyModel.php
Executable file
11
app/FormModel/admin/articles/ModifyModel.php
Executable file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles;
|
||||
|
||||
|
||||
use App\FormModel\admin\articles\trait\ModifyForUpdate;
|
||||
|
||||
class ModifyModel extends BaseModify
|
||||
{
|
||||
use ModifyForUpdate;
|
||||
}
|
12
app/FormModel/admin/articles/module/BaseModule.php
Executable file
12
app/FormModel/admin/articles/module/BaseModule.php
Executable file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles\module;
|
||||
|
||||
class BaseModule
|
||||
{
|
||||
protected array $attributes = [];
|
||||
public function setAttributes()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
8
app/FormModel/admin/articles/module/ShowsModel.php
Executable file
8
app/FormModel/admin/articles/module/ShowsModel.php
Executable file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles\module;
|
||||
|
||||
class ShowsModel
|
||||
{
|
||||
|
||||
}
|
8
app/FormModel/admin/articles/module/StreetModel.php
Executable file
8
app/FormModel/admin/articles/module/StreetModel.php
Executable file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles\module;
|
||||
|
||||
class StreetModel extends BaseModule
|
||||
{
|
||||
|
||||
}
|
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();
|
||||
}
|
||||
}
|
43
app/FormModel/admin/news/NewsFormModel.php
Normal file
43
app/FormModel/admin/news/NewsFormModel.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\news;
|
||||
|
||||
use App\Model\AppNews;
|
||||
|
||||
class NewsFormModel
|
||||
{
|
||||
|
||||
private array $attributes = [];
|
||||
|
||||
public function setAttributes(array $attr, $allowProp = [])
|
||||
{
|
||||
if (!$allowProp) {
|
||||
$this->attributes = $attr;
|
||||
}
|
||||
|
||||
foreach($allowProp as $prop) {
|
||||
if (isset($attr[$prop])) {
|
||||
$this->attributes[$prop] = $attr[$prop];
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function insert()
|
||||
{
|
||||
$model = new AppNews();
|
||||
$model->setRawAttributes($this->attributes);
|
||||
$model->save();
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$model = AppNews::find($this->attributes['id']);
|
||||
$model->title = $this->attributes['title'];
|
||||
$model->keywords = $this->attributes['keywords'];
|
||||
$model->description = $this->attributes['description'];
|
||||
$model->cover = $this->attributes['cover'];
|
||||
$model->content = $this->attributes['content'];
|
||||
$model->save();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user