尽管已声明Laravel路线,但始终未定义

时间:2019-08-09 09:01:26

标签: laravel laravel-5.8

我尝试向我的用户添加一个职位并将其设置在users_positions表上。

我与auth用户create一起创建了一个新查询。将其重新路由到根URL时,总是以

的形式返回

InvalidArgumentException 路线[/]未定义。

控制器

protected function create(array $data)
{

    $id = User::create([
        'firstname' => $data['firstname'],
        'middlename' => $data['middlename'],
        'lastname' => $data['lastname'],
        'email' => $data['email'],
        'username' => $data['username'],
        'password' => Hash::make($data['password']),
    ]);

    DB::table('users_positions')->insert([
        [
            'user_id' => $id->id,
            'position_desc' => $data['position'],
            'primary' => "1",
        ]
    ]);
    return redirect()->route('/')
                    ->with('success', 'Successfully added a user account');
}

路线

Auth::routes();
Route::get('/home', 'HomeController@index')->name('name');

Route::get('/', function () {
    return view('incident-reports.index');
})->middleware('auth');

查询成功,但路由仍未定义。 当我尝试手动转到根URL http://127.0.0.1:8000时。它将起作用。

我的计划是在添加用户和user_position之后,它将返回到根URL,并提示是成功还是错误。

2 个答案:

答案 0 :(得分:6)

如果要使用路径重定向,请将其作为参数发送给redirect()方法

return redirect('/');

route()方法是通过别名重定向到路由

路线

Route::get('/', function () {
    return view('incident-reports.index');
})->middleware('auth')->alias('root');

重定向

return redirect()->route('root');

答案 1 :(得分:3)

更改此行:

<html>
<head>
    <meta charset="utf-8"/>
    <title>Kendo UI Snippet</title>

    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.common.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.rtl.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.silver.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.mobile.all.min.css"/>

    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2019.2.619/js/kendo.all.min.js"></script>
</head>
<body>
<button id="createBtn">Create Shape</button>
<div id="diagram"></div>
<script>
    $("#createBtn").on("click", function(){
      //var count=kendo.dataviz.diagram.Shape().count();
      //alert(count);
      var diagram = $("#diagram").getKendoDiagram();
      var shape = new kendo.dataviz.diagram.Shape({
            type: "circle",
            width: 200,
            height: 200,
            stroke: {
                width: 1,
                color: "#red"
            },
            fill: "#e8eff7",
            editable: true
        });

      var diagram = $("#diagram").getKendoDiagram();
      diagram.addShape(shape);
      diagram.bringIntoView(diagram.shapes);
    });

    var Shape = kendo.dataviz.diagram.Shape;
    $("#diagram").kendoDiagram();
    var diagram = $("#diagram").data("kendoDiagram");

    var shape = new Shape({x: 500, y: 100, fill: "red"});
    diagram.addShape(shape);
</script>
</body>
</html>

对此

return redirect()->route('/')
                ->with('success', 'Successfully added a user account');

return redirect()->to('/') ->with('success', 'Successfully added a user account'); 需要一个路由名称作为参数。 route()是网址