路线[方法]未定义

时间:2015-12-04 04:36:30

标签: laravel-5.1 laravel-routing

我正在创建一个表单来将数据插入到database.version laravel5.1 中,但我的代码无效。 resources\views\login.blade.php

<!-- Registration Form -->
<form action="{{ URL::route('postform_registration') }}" role="form" id="login_popup_form" method="post" name="login_popup_form">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">

    <img id="close" src="{{ URL::asset('tradextek/img/close_irtiza.png') }}" alt="" onclick ="div_hide()">
    <h2>Registration</h2>

    <hr>

    <div class="form-group">
    <label for="">Your Email</label>
    <input type="text" class="form-control" id="login_popup_email" name="login_popup_email" placeholder="Email" type="text">
    </div>

    <hr>

    <div class="form-group">
        <label for="">Your Password</label>
        <input type="password" class="form-control"id="login_popup_password" name="login_popup_password" placeholder="Password...">
    </div>
        <hr>
        <button type="submit" onclick="check_empty()" class="btn btn-primary">Submit</button>
</form>
<h3>
    <?php
    if(Session::has('key')){
        echo Session::get('key');
    }
    ?>
</h3>

routes.php

Route::post('/login',array(
    'as' => 'postform',
    'uses' => 'all_control@postform'
));

Route::post('/login',array(
    'url' => 'postform_registration',
    'uses' => 'all_control@postform_registration'
));

应用程序/控制器/ all_control

public function postform_registration(Request $request)
{
    $email = $request->login_popup_email;
    $password = $request->login_popup_password;
    return redirect('login')->with('key', 'You have inserted successfully');
}

错误消息

1)ErrorException in UrlGenerator.php line 296:
Route [postform] not defined. (View: C:\xampp\htdocs\project\resources\views\login.blade.php)

2)InvalidArgumentException in UrlGenerator.php line 296:
Route [postform] not defined.

1 个答案:

答案 0 :(得分:0)

通过查看此代码,我想,您的错误有两种可能性。

    您已定义的routes.php中的
  1. Route::post('/login',array(
    'as' => 'postform',
    'uses' => 'all_control@postform'
    ));
    Route::post('/login',array(
    'url' => 'postform_registration',
    'uses' => 'all_control@postform_registration'
    ));
    

    我无法理解为什么在您的案例HTTP中有相同网址和相同POST方法的不同路由条目。

  2. 您已为路线

    定义 POST 方法

    Route::post('/login',array( 'as' => 'postform', 'uses' => 'all_control@postform' ));

    另一方面你正在通过 GET 来自控制器的请求。

    和第二点: 您是否在postform中定义了all_control.php