首页 > 解决方案 > 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);
            }```

标签: laravelbrowser-cache

解决方案


您需要将第二个参数从字符串转换为整数

$second_param = (int) '9'.round(microtime(true));
$cookie_uid =  str_pad(rand(0, $second_param),11, "0", STR_PAD_LEFT);

推荐阅读