即使我设置了路由,也没有定义路由

时间:2018-02-09 16:21:55

标签: php laravel routes

我在一个页面中有一个注册表单和一个登录表单:

            <div class="col-md-6 col-centered col-reg">
            <h2>Registreer</h2>
            <form method="post" action="{{ route('signup') }}">
                <div class="form-group {{ $errors->has('regName') ? 'has-error' : '' }}">
                    <label>Naam</label> @if($errors->has('regName')) <span style="color: darkred;">{{ $errors->first('regName') }}</span> @endif<br>
                    <input type="text" name="regName" class="form-control" value="{{ old('regName') }}">
                </div>
                <div class="form-group {{ $errors->has('regEmail') ? 'has-error' : '' }}">
                    <label>Email</label> @if($errors->has('regEmail')) <span style="color: darkred;">{{ $errors->first('regEmail') }}</span> @endif<br>
                    <input type="email" name="regEmail" class="form-control" value="{{ old('regEmail') }}">
                </div>
                <div class="form-group {{ $errors->has('regPassword') ? 'has-error' : '' }}">
                    <label>Wachtwoord</label> @if($errors->has('regPassword')) <span style="color: darkred;">{{ $errors->first('regPassword') }}</span> @endif<br>
                    <input type="password" name="regPassword" class="form-control">
                </div>
                <div class="form-group {{ $errors->has('password_confirmation') ? 'has-error' : '' }}">
                    <label>Nogmaals Wachtwoord</label> @if($errors->has('password_confirmation')) <span style="color: darkred;">{{ $errors->first('password_confirmation') }}</span> @endif<br>
                    <input type="password" name="password_confirmation" class="form-control">
                </div>
                <input type="submit" value="Registreer" name="regSubmit" class="btn btn-primary">
                <input type="hidden" name="_token" value="{{ Session::token() }}">
            </form>
        </div>
        <div class="col-md-6 col-centered col-log">
            <h2>Login</h2>
            <form method="post" action="{{ route('login') }}">
                <div class="form-group">
                    <label>Email</label><br>
                    <input type="email" name="logEmail" class="form-control">
                </div>
                <div class="form-group">
                    <label>Wachtwoord</label><br>
                    <input type="password" name="logPassword" class="form-control">
                </div>
                <input type="submit" value="Login" name="logSubmit" class="btn btn-primary">
                <input type="hidden" name="_token" value="{{ Session::token() }}">
            </form>
        </div>

在表单操作中,我已将链接路由并在web.php中设置它们,如下所示:

Route::group(["prefix" => "forms"], function() {
   Route::post('/', 'PostController@login')->name('login');
   Route::post('/', 'PostController@signUp')->name('signup');
});

但是我收到如下错误消息:

  

路线[登录]未定义

即使我在web.php中创建了它们并将它们分组。

我的路线列表:

Route List

为什么会出现此错误? (顺便说一下laravel的新手)

1 个答案:

答案 0 :(得分:1)

您已经定义了2条路线,这两条路线具有相同的Request Method且具有相同的Route,只是不添加,请尝试:

Route::post('/login', 'PostController@login')->name('login');

如果您不想更改登录网址,可以更改register路由的网址,但重点是您不能拥有两条具有相同请求方法和相同网址的路由