我在我的应用中有一个用于登录的html表单。我不知道为什么我无法在我的控制器中获取表格中的内容。这是我的表格:
<div class="loginContainer">
<form class="signin" method="post" action="/login">
<input type="email" id="inputEmail" placeholder="Email" required="" autofocus="">
<input type="password" id="inputPassword" placeholder="Password" required="">
<button type="submit">Sign in</button>
</form>
</div>
页面/login
重定向以显示此单行:
{&#34;电子邮件&#34;:[&#34;电子邮件字段是必需的。&#34;],&#34;密码&#34;:[&#34;密码 字段是必需的。&#34;]}
这是我的UsersController.php
:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Http\Request;
use App\Users;
use Log;
class UsersController extends Controller
{
public function __construct()
{
// $this->middleware('auth', ['only' => ['authenticate']]);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function authenticate(Request $request)
{
Log::info("hiiidsfoiasjdfisa");
Log::info($request->input('email'));
Log::info($request->input('password'));
Log::info(implode("|", $request->all()));
$this->validate($request, [
'email' => 'required',
'password' => 'required'
]);
$user = Users::where('email', $request->input('email'))->first();
Log::info($user->password);
Log::info($user->email);
if(Hash::check($request->input('password'), $user->password)){
$apikey = base64_encode(str_random(40));
Users::where('email', $request->input('email'))->update(['api_key' => "$apikey"]);;
return response()->json(['status' => 'success','api_key' => $apikey]);
}
else
{
return response()->json(['status' => 'fail'],401);
}
}
}
?>
我尝试记录$request
变量的内容,但所有变量都在日志文件中返回。
请帮忙!
答案 0 :(得分:0)
只需使用输入的名称属性:
<input type="email" name="email" id="inputEmail" placeholder="Email" required="" autofocus="">