Reputation: 73
Im currently learning to do sign in and sign up in laravel8 by referring some tutorials. But after sign up im getting this Undefined offset: 1 message.
Error line that showing is
$iteratee = trim($matches[1]);
This is my route file(web.php)
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
Route::get('/signup',[
'uses' =>'App\Http\Controllers\UserController@getSignup',
'as'=>'user.signup'
]);
Route::post('/signup',[
'uses' =>'App\Http\Controllers\UserController@getSignup',
'as'=>'user.signup'
]);
And this is the signup page register part
<header class="masthead" >
<div class="container">
<div class="masthead-subheading"></div>
<div class="masthead-heading text-uppercase"></div>
<div class="container">
<div class="card bg-light">
<article class="card-body mx-auto" style="max-width: 400px;">
<h4 class="card-title mt-3 text-center">Create Account</h4>
<p class="text-center">Get started with your free account</p>
@if(count($errors) > 0)
<div class="alert alert-danger">
@foreach($errors->all()as $error)
<p>{{$error}}</p>
@endforeach
</div>
@endif
<form action="{{ route('user.signup')}}">
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-envelope"></i> </span>
</div>
<input name="email" class="form-control" placeholder="Email address" type="email">
</div>
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-lock"></i> </span>
</div>
<input name="password" placeholder="Create password" type="password">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block"> Create Account </button>
{{csrf_field()}}
</div> <!-- form-group// -->
<p class="text-center">Have an account? <a href="login.html">Log In</a> </p>
</form>
</article>
</div> <!-- card.// -->
</div>
<!--container end.//-->
</header>
UserController
class UserController extends Controller
{
public function getSignup()
{
return view('user.signup');
}
public function postSignup(Request $request)
{
$this->validate($request,[
'email'=> 'email|required|unique:users',
'password'=>'required|min:4'
]);
$user= new User([
'email'=>$request-> input('email'),
'password'=> bcrypt($request-> input('password'))
]);
$user-->save();
return redirect()->route('shop.index');
}
}
Please teach me a way to solve this.Thank you
Upvotes: 0
Views: 5404
Reputation: 50481
You should add a space in the @foreach
between the pieces:
@foreach($errors->all()as $error)
Should be:
@foreach($errors->all() as $error)
The Blade compiler parses the expression passed to this directive and does a preg_match
on it to get the pieces of the expression as this directive does more than just creating a foreach
loop. Here is the match on the expression:
preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);
$iteratee = trim($matches[1]);
Upvotes: 3