简体   繁体   English

在laravel的voyager管理面板中使用自定义控制器时的数据复制

[英]data duplicating when use custom controller in laravel's voyager admin panel

I use laravel 5.4 and voyager admin panel . 我使用laravel 5.4和voyager 管理面板 There's module I created called recipes. 我创建了一个称为食谱的模块。 I created database table, model and CUSTOM controller and views for this module. 我为此模块创建了数据库表,模型和CUSTOM控制器以及视图。 I also created BREAD, and indicated there my custom controller. 我还创建了BREAD,并在其中指示我的自定义控制器。 the problem is the when I fill form and submit it, data been duplicated in table, I have 2 identical rows in my table every time I create the item. 问题是当我填写表格并提交表格时,数据被复制到表格中,每次创建项目时表格中都有2个相同的行。 I think the problem is that it sends 2 requests, one of requests is from my custom route and controller, and another one is from voyager itself. 我认为问题在于它发送2个请求,一个请求来自我的自定义路线和控制器,另一个请求来自旅行者。 but don't know how to fix it. 但不知道如何解决。

print screen from my BREAD 从我的面包打印屏幕 面包的印刷屏幕

my routes 我的路线

Route::group(['prefix' => 'admin', 'middleware' => ['admin']], function () {

   \Voyager::routes(); //voyager routes

   // routes for my custom module
   // I can comment this routes, but result is the same
   Route::resource('/recipes', 'Admin\RecipesController');

});

my controller 我的控制器

public function store(Request $request)
{
    $recipe = Recipe::create($request->except(['modules']));
    return redirect()
        ->route("recipes.index")
        ->with([
            'message'    => __('voyager.generic.successfully_added_new')." recipe",
            'alert-type' => 'success'
        ]);
}

any idea? 任何想法?

You should try this for check AJax Request : 您应该尝试使用此命令检查AJax Request

public function store(Request $request)
{
    if (!$request->ajax()) {
        $recipe = Recipe::create($request->except(['modules']));

    }
    return redirect()
            ->route("recipes.index")
            ->with([
                'message'    => __('voyager.generic.successfully_added_new')." recipe",
                'alert-type' => 'success'
            ]);
}

the issue was because of form element class form-edit-add , as it seems there was event bound to this class. 问题是由于form元素类form-edit-add ,因为似乎有事件绑定到此类。 I removed it and now it works fine 我删除了它,现在工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM