Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在何处可以找到laravel中的Auth::trument方法_Php_Laravel - Fatal编程技术网

Php 在何处可以找到laravel中的Auth::trument方法

Php 在何处可以找到laravel中的Auth::trument方法,php,laravel,Php,Laravel,在我的Laravel项目中,除了用户的电子邮件和密码之外,我还想向身份验证查询添加额外的条件 我在官方的laravel文件中读到了这一点。 如果希望指定附加条件,还可以添加附加条件 除了用户的 电子邮件和密码。例如,我们可以验证用户是否标记为 “活动”: 在哪里可以找到此方法?AuthController.php <?php namespace App\Http\Controllers; use Auth; use Illuminate\Routing\Controller; cl

在我的Laravel项目中,除了用户的电子邮件和密码之外,我还想向身份验证查询添加额外的条件

我在官方的laravel文件中读到了这一点。

如果希望指定附加条件,还可以添加附加条件 除了用户的 电子邮件和密码。例如,我们可以验证用户是否标记为 “活动”:


在哪里可以找到此方法?

AuthController.php

<?php

namespace App\Http\Controllers;

use Auth;
use Illuminate\Routing\Controller;

class AuthController extends Controller
{
/**
 * Handle an authentication attempt.
 *
 * @return Response
 */
public function authenticate()
{
    if (Auth::attempt(['email' => $email, 'password' => $password])) {
        // Authentication passed...
        return redirect()->intended('dashboard');
    }
}
}

如果您使用Laravel提供的auth脚手架,它将位于AuthenticatesUsers特性中:

/**
 * Attempt to log the user into the application.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return bool
 */
protected function attemptLogin(Request $request)
{
    return $this->guard()->attempt(
        $this->credentials($request), $request->filled('remember')
    );
}

您可以在LoginController中重写此方法。

您需要在LoginController中重写方法登录

public function login(\Illuminate\Http\Request $request) {
    $this->validateLogin($request);

    // If the class is using the ThrottlesLogins trait, we can automatically throttle
    // the login attempts for this application. We'll key this by the username and
    // the IP address of the client making these requests into this application.
    if ($this->hasTooManyLoginAttempts($request)) {
        $this->fireLockoutEvent($request);
        return $this->sendLockoutResponse($request);
    }

    // This section is the only change
    if ($this->guard()->validate($this->credentials($request))) {
        $user = $this->guard()->getLastAttempted();

        // Make sure the user is active
        if ($user->active && $this->attemptLogin($request)) {
            // Send the normal successful login response
            return $this->sendLoginResponse($request);
        } else {
            // Increment the failed login attempts and redirect back to the
            // login form with an error message.
            $this->incrementLoginAttempts($request);
            return redirect()
                ->back()
                ->withInput($request->only($this->username(), 'remember'))
                ->withErrors(['active' => 'You must be active to login.']);
        }
    }

    // If the login attempt was unsuccessful we will increment the number of attempts
    // to login and redirect the user back to the login form. Of course, when this
    // user surpasses their maximum number of attempts they will get locked out.
    $this->incrementLoginAttempts($request);

    return $this->sendFailedLoginResponse($request);
}

您正在调用的为我工作的

Auth::trunt
很可能是
illighted\Auth\SessionGuard@attempt

路径:

Auth::尝试->照亮\Auth\AuthManager->(守卫)照亮\Auth\SessionGuard

Facade->light\Auth\AuthManager@call->@guard->light\Auth\SessionGuard@attempt

为了能够调整为
LoginController
传递的凭据,您只需要覆盖1个方法
credentials
,因为它是传递给
trunt
的数组所涉及的唯一方法

protected function credentials(Request $request)
{
    return $request->only($this->username(), 'password')
        + ['active' => true];
}

你所说的“在哪里找到所提到的方法”是什么意思?这与在LoginController(app/Http/Controllers/Auth/LoginController.php)的数组中添加一个附加元素并覆盖方法authenticate的方法相同。如果您仍然拥有它,execute:php artisan make:authThank,这正是我需要的,我找到了函数credential(request$request),它接受用户名和密码,现在我想向它添加新的参数,例如active=1,Devni将检查它
protected function credentials(Request $request)
{
    return $request->only($this->username(), 'password')
        + ['active' => true];
}