我将Laravel用作离子应用程序的后端,并使用Laravel Passport进行身份验证。当我尝试呼叫#include <stdio.h>
int main()
{
char x = -4;
printf("0x%x -> %i\n", x, x);
x <<= 1; //multiply by 2^1 = 2
printf("0x%x -> %i\n", x, x);
x >>= 2; //divide by 2^2 =4
printf("0x%x -> %i\n", x, x);
return 0;
}
中的0xfffffffc -> -4
0xfffffff8 -> -8
0xfffffffe -> -2
时,显示为createToken()
Login.ts :
Auth
UserController.php :
Call to undefined method
错误日志: 当我使用Postman进行测试时,会引发以下错误
login(event){
let dataJSON;
let formData = new FormData();
formData.append('email',event.target[0].value)
formData.append('password',event.target[1].value)
this.http.post(ENV.BASE_URL+'/auth', formData)
.subscribe((data) => {
console.log(data);
dataJSON = data;
}, (error) => {
console.log("Error!", error);
});
return false;
}
auth.php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Carbon\Carbon;
use App\User;
class UserController extends Controller{
public function auth(Request $request){
$params = $request->only('email', 'password');
$username = $params['email'];
$password = $params['password'];
if(\Auth::attempt(['email' => $username, 'password' => $password])){
$token = \Auth::user()->createToken('Token'); //Throws Error here
return response()->json(['token'=>$token]);
}
return response()->json(['error' => 'Invalid username or Password']);
}
}
user.php
Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Illuminate\Auth\GenericUser::createToken() in file
D:\PsResources\DroidWorkspace\ZiPay\ZipServer\app\Http\Controllers\UserController.php on line 16
Stack trace:
1. Symfony\Component\Debug\Exception\FatalThrowableError->() D:\PsResources\DroidWorkspace\ZiPay\ZipServer\app\Http\Controllers\UserController.php:16
答案 0 :(得分:1)
将这些添加到您的用户模型
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable, HasApiTokens
答案 1 :(得分:0)
尝试一下
\Auth::user()->createToken('Token')->accessToken;
更新:
检查以下内容:
答案 2 :(得分:0)
这很奇怪,我删除了整个项目并重新开始了一个项目,一切正常。