我有一个基于 Laravel 5.4 的网站
我遇到了一个问题,在注册用户时,我需要解决username唯一的英文字母和数字。
我在控制器中有一个方法。
protected function validator(array $data)
{
return Validator::make($data, [
'username' => 'required|string|without_spaces|max:255|unique:users',
'email' => 'string|email|max:255|unique:users|nullable',
'password' => 'string|min:6|confirmed|nullable',
]);
}
Run Code Online (Sandbox Code Playgroud)
有什么想法如何做到这一点吗?我被喂饱了加入规则,alpha_num但事情并没有取得成功。
我有两个关于 Eloquent 的查询,我收集并合并这些查询,然后进行合并,sortByDesc但它没有对集合进行排序。
$f_games = collect(Game::with('fUser', 'sUser')->where('first_user_id', Auth::user()->id)>get());
$s_games = collect(Game::with('fUser', 'sUser')->where('second_user_id', Auth::user()->id)->get());
$response = $f_games->merge($s_games)->sortByDesc('id');
Run Code Online (Sandbox Code Playgroud)