gpt4 book ai didi

laravel - laravel 5.5 改成也有反射(reflect)blade了吗

转载 作者:行者123 更新时间:2023-12-02 03:39:56 24 4
gpt4 key购买 nike

我目前正在将 Laravel 5.4 升级到 5.5,我看到了这个:

has 方法即使输入值为空字符串或 null,$request->has 方法现在也会返回 true。添加了新的 $request->filled 方法,该方法提供了 has 方法之前的行为。

这也适用于 Blade 文件吗?

例如

<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">



@if(session()->has('success'))
<script type="text/javascript">x</script>
@endif

它也会影响文件吗?例如

if ($request->hasFile('images') == false) {
//No image..
}

最佳答案

从版本 5.4 到 5.5 没有任何变化

session()->has('成功')

$errors->has('电子邮件')

$request->hasFile('图像')

从版本 5.4 更改为 5.5

$request->has('某事');

Below source codes are from the official github tags

这是Illuminate\Http(用于$request)

http has() 方法已更改

has() 来自 5.4

/**
* Determine if the request contains a non-empty value for an input item.
*
* @param string|array $key
* @return bool
*/
public function has($key)
{
$keys = is_array($key) ? $key : func_get_args();
foreach ($keys as $value) {
if ($this->isEmptyString($value)) {
return false;
}
}
return true;
}

has() 来自 5.5

/**
* Determine if the request contains a given input item key.
*
* @param string|array $key
* @return bool
*/
public function has($key)
{
$keys = is_array($key) ? $key : func_get_args();
$input = $this->all();
foreach ($keys as $value) {
if (! Arr::has($input, $value)) {
return false;
}
}
return true;
}

hasFile() 相同

hasFile() 来自 5.4

/**
* Determine if the uploaded data contains a file.
*
* @param string $key
* @return bool
*/
public function hasFile($key)
{
if (! is_array($files = $this->file($key))) {
$files = [$files];
}
foreach ($files as $file) {
if ($this->isValidFile($file)) {
return true;
}
}
return false;
}

hasFile() 来自 5.5

/**
* Determine if the uploaded data contains a file.
*
* @param string $key
* @return bool
*/
public function hasFile($key)
{
if (! is_array($files = $this->file($key))) {
$files = [$files];
}
foreach ($files as $file) {
if ($this->isValidFile($file)) {
return true;
}
}
return false;
}

这是Illumnate\Session(用于session())

session has()方法相同

来自 5.4

/**
* Checks if a key is present and not null.
*
* @param string|array $key
* @return bool
*/
public function has($key)
{
return ! collect(is_array($key) ? $key : func_get_args())->contains(function ($key) {
return is_null($this->get($key));
});
}

来自 5.5 的 session

/**
* Checks if a key is present and not null.
*
* @param string|array $key
* @return bool
*/
public function has($key)
{
return ! collect(is_array($key) ? $key : func_get_args())->contains(function ($key) {
return is_null($this->get($key));
});
}

这里是 Illuminate\Support 的 MessageBag.php(针对 $errors)

has() 来自 5.4

/**
* Determine if messages exist for all of the given keys.
*
* @param array|string $key
* @return bool
*/
public function has($key)
{
if (is_null($key)) {
return $this->any();
}
$keys = is_array($key) ? $key : func_get_args();
foreach ($keys as $key) {
if ($this->first($key) === '') {
return false;
}
}
return true;
}

has() 来自 5.5

    /**
* Determine if messages exist for all of the given keys.
*
* @param array|string $key
* @return bool
*/
public function has($key)
{
if (is_null($key)) {
return $this->any();
}
$keys = is_array($key) ? $key : func_get_args();
foreach ($keys as $key) {
if ($this->first($key) === '') {
return false;
}
}
return true;
}

关于laravel - laravel 5.5 改成也有反射(reflect)blade了吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48411933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com