[英]How do I fix an undefined variable error?
我在$validator = $this->validator($input);
定义了变量input
$validator = $this->validator($input);
但这会产生未定义的变量错误。
我的控制器代码如下:
$data = $request->all();
$validator = $this->validator($input);
if($validator->passes()){
$data = $this->create($input)->toArray();
$data['token'] = str_randon[25];
$user = User::find($data['id']);
$user->token = $data['token'];
`enter code here`
$user->save();
Mail::send('mails.confirmation', $data, function($message) use($data){
$message->to($data['email']);
$message->subject('regisrtation sucess and sendt mail');
});
return redirect(route['login'])->with('status', 'confirmation mail');
}
`enter code here`
return redirect(route('login'))->with('status', $validator->error);
`enter code here`
}
public function confirmation($token){
$user = User::where('token', $token)->first();
if(!is_null($user)){
$user->confirmed = 1;
$user->token = '';
$user->save();
return redirect(route('login'))->with('status', 'your activation is complete');
}
return redirect(route('login'))->with('status', 'something rong');
}
您可以使用isset函数检查是否已定义Wheather变量
if(isset($input)) {
if($validator->passes()){
$data = $this->create($input)->toArray();
$data['token'] = str_randon[25];
$user = User::find($data['id']);
$user->token = $data['token'];
`enter code here`
$user->save();
Mail::send('mails.confirmation', $data, function($message) use($data){
$message->to($data['email']);
$message->subject('regisrtation sucess and sendt mail');
});
return redirect(route['login'])->with('status', 'confirmation mail');
}
}
`enter code here`
return redirect(route('login'))->with('status', $validator->error);
`enter code here`
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.