【问题标题】:Form Submit in Laravel Results to 404在 Laravel 结果中提交表单到 404
【发布时间】:2020-01-09 03:41:27
【问题描述】:

我安装了 Laravel,然后将 index.php 从 public 复制到 root 并更改了 index.php 中的一些行。我还复制了htaccess。现在我尝试创建如下所示的路线

我尝试使用 {{ url('signin') }} 和 {{ route('signin') }} 但无济于事

        <form action="{{ route('signin') }}" method="POST">
            {{ csrf_field() }}
            <div>Email: <input type="text" name="username" class="userName textboxes push-right-33"></div>

            <div>Password: <input type="password" name="password" class="password textboxes"></div></br>

            <div class="fpassword-section">
                <a href="#" onclick="return false;" class="forgot-password">Forgot Password</a>
            </div>

            <div class="links">
                <input type="submit" class="button button-signin signin" value="Sign In">
            </div>
        </form>

我的路线将是

Route::any('/signin', 'LoginContoller@authenticateUser')->name('signin');

我的控制器就像

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Illuminate\Support\Facades\Hash;

class LoginContoller extends Controller
{
    public function index(){

        return view('pages.login');

    }

    public function authenticateUser(Request $var){
        echo "string";
    }
}

验证用户不返回任何内容而不是 404

【问题讨论】:

  • “将 index.php 从 public 复制到 root 并更改了 index.php 中的一些行”,但您发布了其他代码。我不知道你没有得到 500。

标签: forms laravel-5 post routes


【解决方案1】:

您传递了错误的 URL。您不需要在 URL 中传递 public。它是基本 URL。

<form action="{{ url('signin') }}" method="POST">

或者如果你想用路由的话。

<form action="{{ route('signin') }}" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>

//route.php define that route as name.
Route::post('/signin', 'LoginContoller@authenticateUser')->name('signin');

【讨论】:

  • 在表单标签下添加{{ csrf_field() }}
  • 也一样。 419未知状态
  • 你能编辑你的问题并给我看表格吗?因为如果你得到 419 错误就意味着 csrf 错误。
  • 你使用的是哪个版本的 laravel?你不知道 laravel Auth 。为什么要手动登录?使用 Auth 登录。
  • 试试这个&lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
猜你喜欢
  • 2017-08-11
  • 1970-01-01
  • 1970-01-01
  • 2021-10-27
  • 2017-12-04
  • 2021-03-30
  • 2016-09-11
  • 1970-01-01
  • 2017-10-07
相关资源
最近更新 更多