Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.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 在ajax laravel登录上设置remember_Php_Ajax_Laravel - Fatal编程技术网

Php 在ajax laravel登录上设置remember

Php 在ajax laravel登录上设置remember,php,ajax,laravel,Php,Ajax,Laravel,使用laravel 5.4重建我的系统。 我做了一个可以工作的ajax登录,但我想将记住选项添加到auth中。 文档中有关于设置的说明,请记住: if (Auth::attempt(['email' => $email, 'password' => $password], $remember)) { // The user is being remembered... } 但由于我的logincontroller没有任何可见的登录功能,因此我正在努力使用当前的loginco

使用laravel 5.4重建我的系统。 我做了一个可以工作的ajax登录,但我想将记住选项添加到auth中。 文档中有关于设置的说明,请记住:

if (Auth::attempt(['email' => $email, 'password' => $password], $remember)) {
    // The user is being remembered...
}
但由于我的logincontroller没有任何可见的登录功能,因此我正在努力使用当前的logincontroller覆盖它。 在我的路线上,我只是打电话LoginController@login. 我对正在调用的登录函数没有覆盖

这是我的登录控制器:

namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;

use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;
class LoginController extends Controller
{

    use AuthenticatesUsers;
    protected $redirectTo = '/minside';
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }
    protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();
        $this->clearLoginAttempts($request);
        if ($request->ajax()) {
            error_log($this->guard()->user(),'0');
            return response()->json($this->guard()->user(), 200);
        }
        return $this->authenticated($request, $this->guard()->user())
            ?: redirect()->intended($this->redirectPath());
    }
    protected function sendFailedLoginResponse(Request $request)
    {
        if ($request->ajax()) {
            return response()->json([
                'error' => Lang::get('auth.failed')
            ], 401);
        }
        return redirect()->back()
            ->withInput($request->only($this->username(), 'remember'))
            ->withErrors([
                $this->username() => Lang::get('auth.failed'),
            ]);
    }
}

使用Laravel提供的LoginController类时,它会执行以下检查:

protected function attemptLogin(Request $request)
{
    return $this->guard()->attempt(
        $this->credentials($request), $request->has('remember')
    );
}

只需在您的请求中包含“
记住”
,以记住用户登录名。

谢谢,但在我的logincontroller中该怎么做?我不知道我到底在哪里进行身份验证在这一点上,我在我的表单中添加了一个remember_me,它满足了我的需要,但我希望对我的logincontroller有更多的控制。logincontroller使用了trait AuthenticatesUsers,它具有attemptLogin功能。如果你想拥有更多的控制权,你可以重写函数,创建你自己的特性,或者只创建你自己的控制器;)