laravel - laravel 错误:rand() 期望参数 2 为 int, string
问题描述
php artisan serve
在 laravel 项目上清除和配置缓存后面临错误托盘运行rand() expects parameter 2 to be int, string given (View: C:\Users\user\Desktop\traipler-fe\traipler-fe\resources\views\traipler\region\jscontainer.blade.php)
jscontainer.blade.php
$cookie_uid =(\Cookie::get('tr_uid')?\Cookie::get('tr_uid'):'');
if( $user = \Auth::user()){
$cookie_uid = $user->id;
}
('set', 'userId', 'USER_ID'); // Set the user ID using signed-in user_id.
if(empty($cookie_uid)){ //CREO UN COOKIED ID TEMPORANEO
//$cookie_uid = uniqid();
$cookie_uid = str_pad(rand(0,'9'.round(microtime(true))),11, "0", STR_PAD_LEFT);
Cookie::queue('tr_uid', $cookie_uid, 525600);
}```
解决方案
您需要将第二个参数从字符串转换为整数
$second_param = (int) '9'.round(microtime(true));
$cookie_uid = str_pad(rand(0, $second_param),11, "0", STR_PAD_LEFT);
推荐阅读
- mongodb - MongoDB:与数组中的元素匹配
- mysql - Doctrine\DBAL\DBALException "执行带有参数 [...] 的 '...' 时发生异常警告:发送 QUERY 数据包时出错。PID=
- python - 如何在 Tkinter 上将图像锁定到背景?(Python)
- postgresql - 使用 Navicat 远程管理 PostgreSQL 数据库
- android - 如何在 Android 上使用 Apollo 读取 GraphQL HTTP 响应标头?
- sql - 在 SQL 的报表生成器查询中将字符串转换为日期/时间
- python - Python:比较字符串列表的元素,根据相似度排序
- c# - EMGU 安装问题
- rxjs - 根据条件按顺序执行可观察对象数组
- sql - 链表:查询存储在 SQL 表中的链表的第一个和最后一个元素