小编Pif*_*fek的帖子

添加到控制器的内容和添加到模型的内容

我有一个小问题。哪些数据保存在控制器中,哪些数据保存在模型中?我知道在模型中保留了应用程序的整个逻辑等,但是查询和帮助函数是什么?例如

控制器:

public function add(Request $request)
{
    $item = new Item()
    $item->name = $request->name;
    $item->save();

    $this->makeDirectory();
}

private function makeDirectory()
{
    //make a directory with photo this product
}
Run Code Online (Sandbox Code Playgroud)

我应该在哪里保留控制器或模型中的“makeDirecory”方法?

这是我从另一个表中删除产品和参考的另一种情况。

public function delete(Items $id)
{
    $id->delete();

    $this->deleteProperties($id->properties); // $id->properties is a method from Items model with references to table Properties
}

private function deleteProperties(Properties $id)
{
    $id->delete();
}
Run Code Online (Sandbox Code Playgroud)

我应该在控制器、项目模型还是属性模型中保留“deleteProperties”方法?并从这个模型调用这个方法?

php methods model-view-controller private laravel

6
推荐指数
1
解决办法
1381
查看次数

标签 统计

laravel ×1

methods ×1

model-view-controller ×1

php ×1

private ×1