【问题标题】:Route [method] not defined路线[方法]未定义
【发布时间】:2016-03-08 22:50:42
【问题描述】:

我正在创建一个表单以将数据插入到 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'
));

app/controllers/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.

【问题讨论】:

    标签: laravel-5.1 laravel-routing


    【解决方案1】:

    看到这段代码,我猜你的错误有两种可能。

    1. 在你定义的 routes.php 中:

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

      我不明白为什么在你的案例POST 中,相同的 url 和相同的 HTTP 方法有不同的路由条目。

    并且您已经为 routes

    定义了 POST 方法

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

    你正在传递来自控制器GET请求。

    第二点: 你在all_control.php中定义了postform吗?

    【讨论】:

    • Route::post('/login',array( 'as' => 'postform', 'uses' => 'all_control@postform' ));这是我项目中的第一种形式,第二种有错误。我想通过 postform_registration 方法捕获电子邮件、密码
    • Route::post('/login',array( 'as' =&gt; 'postform', 'uses' =&gt; 'all_control@postform' )); 如果这是用于显示登录表单,那么您必须在路由中使用 get 方法而不是 post 方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    • 2016-08-26
    • 2021-11-12
    • 2022-01-16
    • 2018-10-15
    • 2020-09-13
    • 2017-12-25
    相关资源
    最近更新 更多