phpstorm为laravel 添加自动完成

Facade 添加自动完成

详情可访问github项目

https://github.com/barryvdh/laravel-ide-helper

配置:

下载gist文件到项目根目录

wget https://gist.githubusercontent.com/barryvdh/5227822/raw/4be028a27c4ec782965bb8f2fdcb4c08c71a441d/_ide_helper.php

添加ignore

vim .gitignore
#添加
_ide_helper.php

保存即可完成

mysql 随机生成不重复的数字

在用户表的 username 生成8位不重复的数字

mysql

SELECT FLOOR(RAND() * 999999999) AS random_num
FROM user 
WHERE "random_num" NOT IN (SELECT username FROM user)
LIMIT 1

用laravel实现

UserModel.php

use Illuminate\Database\Query\Expression;
$user = new User();
$res = $user->selectRaw("FLOOR(RAND() * 999999999) AS random_num")
        ->whereNotIn(new Expression('"random_num"'), $user->select('username'))->value('random_num');

返回

float(随机8位数字)