php – Laravel响应代码和消息
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Laravel响应代码和消息,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1550字,纯文字阅读大概需要3分钟。
内容图文
![php – Laravel响应代码和消息](/upload/InfoBanner/zyjiaocheng/746/48265ebc691c4695a3819feedccb0921.jpg)
我正在使用Laravel 5.3和https://github.com/1000hz/bootstrap-validator
我正在检查Laravel中我的数据库的用户电子邮件,以检查电子邮件是否正在使用中.
Bootstrap Validator上的文档声明如果电子邮件地址正常(即不存在)则返回200,如果存在则返回4xx错误.
在我的Laravel功能中,我正在执行以下操作:
public function check_email(Request $request)
{
// Email Address
$email = User::where('email', $request->input('email'))
->take(1)
->get();
$email = $email->toArray();
if(empty($email))
{
return response()->json(['Email Not Taken'], 200);
}
else
{
return response()->json(['Email In Use'], 400);
}
}
现在当我运行验证器时,它没有显示消息.这是因为Laravel对其响应代码更加严格吗?或者我只是做错了什么?
我的HTML代码如下:
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" placeholder="Email" data-remote="/validate-email" data-error="Please enter your Email Address" required="required">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span><!-- /.help-block -->
@endif
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
<div class="help-block with-errors"></div>
</div><!-- /.form-group -->
如何在Larvel 5.3中使用消息设置4xx响应?
谢谢
解决方法:
首先,不要通过查询检查用户是否存在使用Laravel的验证器类https://laravel.com/docs/5.3/validation它已经为您完成了这项工作,请参阅:https://laravel.com/docs/5.3/validation#rule-unique
其次,看看这个库已经完成了你需要的工作:https://github.com/proengsoft/laravel-jsvalidation
内容总结
以上是互联网集市为您收集整理的php – Laravel响应代码和消息全部内容,希望文章能够帮你解决php – Laravel响应代码和消息所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。