token = Auth::refresh(); $user->token_ttl = config('jwt.ttl'); $user->is_password = !empty($user->password)?1:0; $fractal = new Manager(); $res = new Item($user,new LoginTransformer()); $array = $fractal->createData($res)->toArray(); //同一类型登陆只允许登陆一个 return $this->jsonSuccess($array); } /** * 登出 * @return mixed */ public function logout() { Auth::logout(); return $this->jsonSuccess([],'登出成功'); } //登陆 public function login(Request $request){ $data = $request->all(); $validator = Validator::make($data, [ 'account' => 'required|max:50', 'password' => 'required|max:32', ]); if ($validator->fails()) { return $this->jsonError($validator->errors()->first()); } $account = ShopAccount::where('account',$data['account'])->first(); if(!$account){ return $this->jsonError('登录失败,请重试'); } $token = Auth::attempt(['mobile'=>$request->get('mobile'),'password'=>$request->get('password')]); if(!$token){ return $this->jsonError('登陆失败'); }else{ $shopAccount = Auth::user(); $shopAccount->token = $token; $shopAccount->token_ttl = config('jwt.ttl'); //如果有绑定微信,显示微信open_id $fractal = new Manager(); $res = new Item($shopAccount,new LoginTransformer()); $array = $fractal->createData($res)->toArray(); //日志 return $this->jsonSuccess($array); } } }