refactor(controller): instantiate model class instead of assigning model name

- Change {{modelFilename}}::class to new {{modelFilename}}() in controller constructor- This modification allows direct access to model properties and methods
This commit is contained in:
wolfcode
2025-05-14 12:32:02 +08:00
parent 1b3265aeb5
commit 61e622d2ad
2 changed files with 2 additions and 2 deletions

View File

@@ -24,7 +24,7 @@ class Goods extends AdminController
public function __construct(App $app)
{
parent::__construct($app);
self::$model = MallGoods::class;
self::$model = new MallGoods();
$this->assign('cate', MallCate::column('title', 'id'));
}

View File

@@ -16,7 +16,7 @@ class {{controllerName}} extends AdminController
public function __construct(App $app)
{
parent::__construct($app);
self::$model = {{modelFilename}}::class;
self::$model = new {{modelFilename}}();
$notes = self::$model::$notes;
{{constructRelation}}
$this->notes =$notes;