本文整理匯總了PHP中App\Http\Controllers\Auth::validate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Auth::validate方法的具體用法?PHP Auth::validate怎麽用?PHP Auth::validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類App\Http\Controllers\Auth
的用法示例。
在下文中一共展示了Auth::validate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: postLogin
public function postLogin()
{
$token = '1kcna4n93-mc29023hfhfb3497cb3287s';
$username = \Input::get('username');
$password = \Input::get('password');
if (\Auth::validate(['username' => $username, 'password' => $password])) {
$user = \App\User::where('username', $username)->first();
if ($user) {
$userArray = $user->toArray();
$userArray['api_key'] = $token;
return $userArray;
} else {
return response()->json(['error' => 'Incorrect credentials']);
}
}
}
示例2: login
public function login()
{
// Getting all post data
$data = Input::all();
// Applying validation rules.
$rules = array('email' => 'required|email', 'password' => 'required|min:6');
$validator = Validator::make($data, $rules);
if ($validator->fails()) {
// If validation falis redirect back to login.
return Redirect::to('admin/login')->withInput(Input::except('password'))->withErrors($validator);
} else {
$userdata = array('email' => Input::get('email'), 'password' => Input::get('password'));
// doing login.
if (Auth::validate($userdata)) {
if (Auth::attempt($userdata)) {
return Redirect::intended('/categories');
}
} else {
// if any error send back with message.
Session::flash('error', 'Something went wrong');
return Redirect::to('admin/login');
}
}
}