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')".
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!