私はLaravelを初めて使い、非常に単純なログインフォームを作成しようとしています.
このフォームには「Remember Me」チェックボックスがあります。を使用してその機能を実装しようとしましたが、保存するにはCookie::make()
a を返す必要があることがわかりました。Response
ブラウザに保存されている Cookie を確認localhost
すると、 という名前の Cookie が見つかりませんusername
。私はいくつかの調査を行いましたが、Cookie を a に添付して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', 'ActionController@showForm');
Route::post('signup', 'ActionController@processForm');
Route::get('result', 'ActionController@showResult');