我是Laravel的新手,在这里,我正在尝试制作一个简单的注册和登录表格,在注册和登录表格无法正常工作之前。但是当我决定在name
,email
和password
中进行验证时,它给了我这个错误,任何帮助将不胜感激...
谢谢
“未定义的偏移量:1”
HTML
@extends("layouts.master")
@section('title')
My page
@endsection
@section('content')
@if(count($errors)>0)
<div class ="row">
<div class="col-md-6">
<ul>
@foreach($errors->all()as $error)
<li>{{"$error"}}</li>
@endforeach
</ul>
</div>
</div>
@endif
<div class="row">
<div class="col-md-6">
<h3>Sign-Up</h3>
<form action="{{route('signup')}}" method="post">
<div class="form-group">
<label for="email">Your email</label>
<input class="form-control" type="text" name="email" id="email">
</div>
<div class="form-group">
<label for="first_name">First Name</label>
<input class="form-control" type="text" name="first_name" id="first_name">
</div>
<div class="form-group">
<label for="password">Password</label>
<input class="form-control" type="password" name="password" id="password">
</div>
<button type="sumbit" class="btn btn-primary">sumbit</button>
<input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
</div>
<div class="col-md-6">
<h3>Login </h3>
<form action="{{route('signin')}}" method="post">
<div class="form-group">
<label for="email">Your email</label>
<input class="form-control" type="text" name="email" id="email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input class="form-control" type="password" name="password" id="password">
</div>
<button type="sumbit" class="btn btn-primary">sumbit</button>
<input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
</div>
</div>
@endsection
控制器
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\User;
use App\UserTypes;
use Auth;
use Hashids;
use Redirect;
use Illuminate\Http\Request;
use Hash;
class UserController extends controller
{
public function getdashboard()
{
return view('dashboard');
}
public function postSignUp(Request $request)
{
$request->validate([
'email' => 'required|email|unique:users',
'first_name' => 'required|max:120',
'password' => 'required|min:4'
]);
$email = $request->email;
$first_name = $request->first_name;
$password = bcrypt($request->password);
$user = new User();
$user->email = $email;
$user->first_name = $first_name;
$user->password = $password;
$user->save();
return redirect()->route('dashboard');
}
public function postSignIn(Request $request)
{
if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) {
return redirect()->route('dashboard');
}
return redirect()->back();
}
}