Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nasr1's avatar
Level 1

get user object in post man

Hello guys , i was able to make api for registration and login , i made it using passport , but now in the postman when i use the login URL , it give me the access token , token type ,expired in ,refresh token .. but i need beside this info , the registration object information , like his user name , email , etc how i do that , knowing am new to laravel thank u very much good people :)

0 likes
2 replies
MadMikeyB's avatar

By default Laravel ships with an routes/api.php file which contains the /api/user route - this should show you how to return the current user.

If you want to return the user object of any user, I would say to modify that route to use the User model and just return the model. Laravel will cast it to JSON for you.

Something like

return \App\User::find(1)->first();

inside a controller (or closure) would work fine.

It's worth noting that the routes/api.php has it's own middleware which needs satisfying before anything gets through.

Nasr1's avatar
Level 1

@MadMikeyB thk bro for answering me , this my registerController method code public function register(Request $request) { $this->validate($request, [ 'name'=>'required', 'email'=>'required|email|unique:users,email', 'password'=>'required|min:6|confirmed' ]);

    $user=User::create([
        'name'=>request('name'),
        'email'=>request('email'),
        'password'=>bcrypt('password')
    ]);

    $params = [
        'grant_type'=>'password',
        'client_id'=>$this->client->id,
        'client_secret'=>$this->client->secret,
        'username'=>request('email'),
        'password'=>request('password'),
        'scope'=>'*'
    ];
    $request->request->add($params);
    $proxy=Request::create('oauth/token','POST');
    return Route::dispatch($proxy); 
    //dd($request->all());
}

} and this is the login controller code : public function login(Request $request) { $this->validate($request,[ 'username'=>'required', 'password'=>'required' ]);

    $params = [
        'grant_type'=>'password',
        'client_id'=>$this->client->id,
        'client_secret'=>$this->client->secret,
        'username'=>request('username'),
        'password'=>request('password'),
        'scope'=>'*'
    ];
    $request->request->add($params);
    $proxy=Request::create('oauth/token','POST');

    
    return Route::dispatch($proxy); 

}

so what should i change in the login method code so that not only it return the token_key and refresh token but also the user registration info it self like user name and email and password etc, thks again bro :)

Please or to participate in this conversation.