我有一個laravel應用程序,我想限制僅註冊到擁有公司電子郵件的特定目標組的用戶。我已經試過的東西在我的Registrar.php
Laravel註冊。只註冊擁有來自特定域的電子郵件的用戶
public function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'lastname' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
public function create(array $data)
{
$result = null;
$confirmation_code = str_random(30);
$data = array_add($data, 'conf',$confirmation_code);
if(!$data['email'].ends_with(('email'), 'specificdomain.com')){
Flash::message('Welcome ' .$data["name"]. '. Thanks for registering. We have sent you a validation link in your e-mail address!');
Mail::send('emails.verify', $data, function($message) use ($data) {
$message->to($data['email'], $data['name'])
->subject('Verify your email address');
});
$result = User::create([
'name' => $data['name'],
'lastname' => $data['lastname'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'confirmation_code' => $confirmation_code
]);
}else{
$result = Flash::warning('Hi ' .$data["name"]. '. We appreciate your interest on using our System. However at the moment we offer this service only to this company!');
//break;
}
return $result;
}
這引發以下異常
Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, Laracasts/Flash/Flash given.
,我不能在else語句打破,因爲我得到如下:
Cannot break/continue 1 level
顯然,我有到return Users::create([....])
但要這樣做,我必須保持此塊以外的if語句。如果我這樣做,我不能檢查電子郵件域是否是必需的。所以我問,我怎樣才能把它整合到public function validator(array $data){.....}
區塊?
所有的幫助表示讚賞。
創建函數將用戶存儲在數據庫中。如果我沒有返回用戶,那麼比我在問題 – xhulio
中發佈的第一個錯誤可以請您更新您的問題與您調用登錄功能的代碼?我想你應該只登錄,如果你得到一個用戶作爲結果。 –
我認爲你誤解了這個問題。這是註冊部分,而不是登錄。儘管我剛剛嘗試過並按預期工作,但您的解決方案仍然有效非常感謝:) – xhulio