我想在输入值中显示旧的输入.如果没有旧输入,则显示其他变量:

value="{{ old('salary_' . $employee->id) or 'Default' }}"

But when there is no old input, it gives me 1 instead of the default value!

I think the problem has something to do with the concatenation, but I don't know how to fix it!?

推荐答案

or is a comparison operator in PHP, so your code is evaluating to true, or 1. What you want is a ternary if statement.

As mentioned, or can be used in blade as shorthand for a ternary if statement.

但您可以(也应该)将默认值作为第二个参数传递给函数,如下所示:

value="{{ old('salary_' . $employee->id, 'Default') }}"

Laravel相关问答推荐

使用MAATWebSite/EXCEL导入Exel时,不会创建Laravel模型

Laravel 联合和分页

如何在 Laravel 中获取特定月份的最后一个日期?

Laravel中如何动态更改路由链接?

如何计算具有特定 ID Laravel 的行

前端和管理员分开时未加载laravel 9中间件

向 Laravel 模型查询添加计算字段

覆盖 HTTP 标头的默认设置 (X-FRAME-OPTIONS)

Laravel 5.4 中的自定义助手类

.gitignore 不忽略文件夹

如何使用 Eloquent Laravel 更新集合

PHP 中的 Http 响应代码枚举

Laravel 生产问题 - 使用 Laravel 4.1.x 更新composer

将 Laravel 集合附加到另一个集合

配置和测试 Laravel 任务调度

Laravel 5.4 Vue.JS 无法挂载组件:未定义模板或渲染函数

在 laravel Passport 客户端应用程序中使用访问令牌获取用户数据

如何判断 Laravel 集合是否为空?

如何在 Laravel 5 中验证 RESTful API?

为什么`catch (Exception $e)` 不处理这个`ErrorException`?