本文整理汇总了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');
}
}
}