我是Laravel的新手,试图制作一个非常简单的登录表单。使用Laravel实现“记住我”功能4
此表单有一个“记住我”复选框。我试图用Cookie::make()
来实现它的功能,但事实证明我需要返回一个Response
以保存它。
当我在我的浏览器中检查从localhost
存储的Cookie时,我没有找到名为username
的cookie。我做了一些调查,结果发现我必须将cookie放入Response
然后返回。
问题是,我不想返回一个Response
!
我在学习过程中尚未达到Auth
班。所以没有使用这个类的解决方案会更合适。
这里是我的代码:
public function processForm(){
$data = Input::all();
if($data['username'] == "rafael" & $data['password'] == "123456"){
if(Input::has('rememberme')){
$cookie = Cookie::make('username', $data['username'], 20);
}
Session::put('username', $data['username']);
return Redirect::to('result');
} else {
$message_arr = array('message' => 'Invalid username or password!');
return View::make('signup', $message_arr);
}
}
我signup.blade.php
:
@extends('layout')
@section('content')
@if(isset($message))
<p>Invalid username or password.</p>
@endif
<form action="{{ URL::current() }}" method="post">
<input type="text" name="username"/>
<br>
<input type="text" name="password"/>
<br>
<input type="checkbox" name="rememberme" value="true"/>
<input type="submit" name="submit" value="Submit" />
</form>
@stop
routes.php
:
Route::get('signup', '[email protected]');
Route::post('signup', '[email protected]');
Route::get('result', '[email protected]');