Home  >  Article  >  PHP Framework  >  How to use has method in laravel

How to use has method in laravel

WBOY
WBOYOriginal
2021-12-24 09:40:393306browse

The has method in laravel can be used to query whether there is a relationship between data. It is often used to determine whether the current request contains a specified value. If the value exists in the request, the has() method will return true. When When an array is given, this method will determine whether all specified values ​​exist. The syntax is "has('name')".

How to use has method in laravel

The operating environment of this tutorial: Windows 10 system, Laravel 6 version, DELL G3 computer.

How to use the has method in laravel

has determines whether the input value exists
You can use has to determine whether the current request contains the specified value. If the value exists in the request, the has method will return true:

if ($request->has('name')) {
//
}

When an array is given, has will determine whether all the specified values ​​exist:

if ($request->has(['name', 'email'])) {
//
}

hasAny The method will return true if the specified value exists:

if ($request->hasAny(['name', 'email'])) {
//
}

Supplementary instructions

If you want to determine whether a value exists in the request, and it is not If empty, you can use the filled method:

if ($request->filled('name')) {
//
}

If you want to determine whether a value is missing in the request, you can use the missing method:

if ($request->missing('name')) {
//
}

Related recommendations: The latest five Laravel video tutorials

The above is the detailed content of How to use has method in laravel. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn