Home > PHP Framework > Laravel > body text

How to use has method in laravel

WBOY
Release: 2021-12-28 11:24:16
Original
3351 people have browsed it

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')) {
//
}
Copy after login

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

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

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

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

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')) {
//
}
Copy after login

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

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!