在 MySQL 数据库中,我使用 tinyint(1),因此验证字段将为 0 或 1。 我如何编辑下面的推力以使其能够显示 True 或 False 而不是 0 或 1?
namespace App\Thrust;
use BadChoice\Thrust\Resource;
use BadChoice\Thrust\Fields\Link;
use BadChoice\Thrust\Fields\Text;
use BadChoice\Thrust\Fields\Email;
use BadChoice\Thrust\Fields\Gravatar;
class Requester extends Resource
{
public static $model = \App\Requester::class;
public static $search = ['name', 'email'];
public static $defaultSort = 'tickets_count';
public static $defaultOrder = 'DESC';
public function fields()
{
return [
Text::make('validate', 'Validate'),
];
}
}
最佳答案
您正在寻找的功能称为 Type Casting .
The meaning of type casting is to use the value of a variable with different data type. In other word typecasting is a way to utilize one data type variable into the different data type. Source
例子
$response = 1;
var_dump($response); // Output: int(1)
var_dump((bool)$response); // Output: bool(true)
另一个例子可能是当你构建一个函数并使用它时你正在获取 1/0
值,如果你想将它作为 boolean
类型返回可以在里面做。例如:
public function isValid((string) $query): boolean
{
$result = some_check($query);
return (boolean) $result;
}
其他可能的数据类型转换是:
(int), (integer) - cast to integer
(bool), (boolean) - cast to boolean
(float), (double), (real) - cast to float
(string) - cast to string
(array) - cast to array
(object) - cast to object
关于php - Laravel Text 不显示 True/False,而是 0/1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59764921/