当我运行create()
来从我的RegisterController
创建用户时,它返回419
错误。我一直在尝试使用JWT设置auth令牌,它尚未完全完成,我正在尝试设置我的注册控制器,以便我可以注册用户并登录。
注意:当我运行我的注册终点时,它会生成一个令牌(我不知道为什么)
我正在使用laravel 5.5
和
"tymon/jwt-auth": "1.0.0-rc.1"
RegisterController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Consumer;
//use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
use RegistersUsers;
// public function __construct()
// {
// $this->middleware('guest');
// }
protected function validator(array $data)
{
return Validator::make($data, [
'con_fname' => 'required|string|max:255',
'con_lname' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:consumers',
'password' => 'required|string|min:6|confirmed',
]);
}
protected function create(array $data)
{
return Consumer::create([
'con_fname' => $data['con_fname'],
'con_lname' => $data['con_lname'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'con_cover_photo' => null,
'con_profile_pic' => null
]);
}
}
api.php
<?php
use Illuminate\Http\Request;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::resource('business', 'BusinessController');
Route::resource('consumer', 'ConsumerController');
Route::post('register', 'RegisterController@create');
Route::group([
'middleware' => 'api',
'prefix' => 'auth'
], function ($router) {
Route::post('login', 'AuthController@login');
Route::post('logout', 'AuthController@logout');
Route::post('refresh', 'AuthController@refresh');
Route::post('me', 'AuthController@me');
});
END POINT(在邮差中运行)
http://localhost:8000/register
我的帖子人端点的正文
{
"email": "user1@gmail.com",
"password": "password",
"password_confirmation": "password",
"con_fname": "john",
"con_lname": "doe"
}