Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree的儲存$form->isCreating()會判斷為true #60

Closed
lilashih opened this issue Apr 30, 2020 · 5 comments
Closed

tree的儲存$form->isCreating()會判斷為true #60

lilashih opened this issue Apr 30, 2020 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@lilashih
Copy link
Contributor

  • Laravel Version: 7.8.1
  • PHP Version: 7.2.6
  • Dcat Admin Version: 1.2.0

Description:

image

點擊tree的儲存時$form->isCreating()會判斷為true,可能是因為送出的是post

$form->saved(function (Form $form) {
    dd('$form->isCreating() : '.$form->isCreating());
});

image

Steps To Reproduce:

@jqhph jqhph added the bug Something isn't working label Apr 30, 2020
@jqhph
Copy link
Owner

jqhph commented Apr 30, 2020

感谢反馈

@jqhph
Copy link
Owner

jqhph commented May 2, 2020

刚才检查了下代码,模型树保存排序的功能是没有带行ID的,所以严格来说这个并不算问题。不知道你想要saved事件中用isCreating判断做什么?

@jqhph jqhph removed the bug Something isn't working label May 2, 2020
@lilashih
Copy link
Contributor Author

lilashih commented May 2, 2020

用來判斷要更新創建者還是編輯者

$form->saved(function (Form $form, $result) {
    if ($form->isCreating()) {
        event(new CreatorUpdated($form->repository()->eloquent(), Admin::user()));
    } else {
        event(new UpdaterUpdated($form->repository()->eloquent(), Admin::user()));
    }
});

@jqhph
Copy link
Owner

jqhph commented May 2, 2020

用來判斷要更新創建者還是編輯者

$form->saved(function (Form $form, $result) {
    if ($form->isCreating()) {
        event(new CreatorUpdated($form->repository()->eloquent(), Admin::user()));
    } else {
        event(new UpdaterUpdated($form->repository()->eloquent(), Admin::user()));
    }
});

看你这个像是操作日志,也许可以这样使用

$form->saved(function (Form $form, $result) {
     if (request()->get('_order') && $form->isCreating()) {
         // 保存排序操作
      
    } elseif ($form->isCreating()) {
        event(new CreatorUpdated($form->repository()->eloquent(), Admin::user()));
    } else {
        event(new UpdaterUpdated($form->repository()->eloquent(), Admin::user()));
    }
});

@jqhph jqhph added the help wanted Extra attention is needed label May 2, 2020
@lilashih
Copy link
Contributor Author

lilashih commented May 2, 2020

好的 這樣應該OK 感謝~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants