本文介绍了如何在laravel上区分请求为空字符串和null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在php中我们可以做到
in php we can do
isset($_POST['name'])以便可以检测到用户提交空文本.
so that user submit empty text can be detected.
但在laravel中
$request->has('name')空字符串也返回null.
return null on empty string too.
我需要找到一种方法来判断它是一个空字符串还是该字段根本不发布
I need to find a way to tell if it is an empty string or the field not posted at all
推荐答案您可以在请求实例中使用exist()方法.如果要检查请求检查中是否有值:
You can use exists() method in request instance. If you want to check if there is value in request check:
$request->has('key');如果要检查密钥是否存在,请使用:
if you want to check if the key is exists use:
$request->exists('key');更多推荐
如何在laravel上区分请求为空字符串和null
发布评论