为新用户设置API令牌Lumen / Laravel

时间:2018-12-20 09:53:28

标签: laravel api lumen

我正在开始使用流明。

这是我的web.php文件

$router->group(['prefix' => 'api'], function () use ($router) {

    $router->post('user', ['uses' => 'UserController@createUser']);

});

这是我的UserController.php

public function createUser(Request $request){

    $this->validate($request, [
        'username' => 'required',
        'password' => 'required|min:3'
    ]);
    $user = [
        'username' => $request->username,
        'password' => app('hash')->make($request->password),
        'email' => $request->email,
        'api_token' => 'asdfasd' //want should I put here
    ];

    $user = User::create($user);


    return response()->json($user, 201);
}

如何为正在注册的新用户创建新的api令牌?

0 个答案:

没有答案