douxing9567 2017-09-22 15:33
浏览 23

Laravel - 控制器没有从表单中获取请求

I have this form:

<form action="{{route('login')}}" id="loginForm" method="POST">
           <div class="text-center" style="font-size: 30px; font-family: 'Poppins', sans-serif;">Login</div><br />
        <div class="input-group">
            <span class="input-group-label"><i class="fa fa-envelope"></i></span>
            <input class="input-group-field" id="lemail" name="lemail" placeholder="Insert your email" type="email" required>
        </div>
        <p class="help-text" id="email">Type in your email and password to log in.</p>

        <div class="input-group">
            <span class="input-group-label"><i class="fa fa-lock"></i></span>
            <input class="input-group-field" id="lpassword" name="lpassword" placeholder="Type in your password" type="password" required>
        </div>

        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <br />
        <div class="align-center">
        <button type="submit" class="button secondary align-center" href="#">Login</button>
        </div>
    </form>

As you see, I have action="{{route('login')}}" as I want to use that route:

Route::post('/', [
   'as' => 'login',
   'uses' => 'LoginUser@login'
]);

And this is the function:

public function login(Request $request)
    {
        $this->validate($request, [
            'lemail' => 'required|string|email|max:255',
            'lpassword' => 'required|string|min:6|max:128',
        ]);

        $email = $request->input('lemail');
        $password = $request->input('lpassword');

        if (Auth::attempt(['email' => $email, 'password' => $password])) {

            // Authentication passed...
            return redirect()->intended('/home')
                ->with('flash_notice', 'You are successfully logged in.');
        }

        return redirect()->intended('/')
            ->with('flash_error', 'Your username/password combination was incorrect.');
    }

The problem is that after I fill the fields and send the form, it tells me that the email and password fields are empty, but they are not.

This only happens if I set the "action" and do the route like that, otherwise it works fine.

I did this because I have it in the footer and I want it to work on all pages, but I can't get it to work.

  • 写回答

2条回答 默认 最新

  • douao3063 2017-09-22 15:45
    关注

    Use your route as:

    Route::post('/', 'LoginUser@login')->name('login');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口