Laravel如何使用auth:user()

时间:2018-07-19 17:42:21

标签: php laravel eloquent laravel-passport

从最近几天开始,我开始通过Passport学习Laravel,并关注了这篇精彩的文章Create REST API in Laravel with authentication using Passport

我已经创建了登录,注册,详细列表API,但是在登录API中,我试图返回JSON中已登录的用户详细信息,并且它返回所有信息,但是我只想id, name, email, phone,所以如何申请{{ 1}}在select('id', 'name', 'email', 'phone')

我可以使用PHP取消设置功能轻松删除数据,但我不想使用它。我只想选择需要的列,这样可以吗?

我的控制器源代码:

$user = Auth::user()

API JSON结果:

<?php

namespace App\Http\Controllers\API;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;

class PassportController extends Controller
{
    public function login()
    {
        if (Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
            $user = Auth::user();
            $success['token'] = $user->createToken('MyApp')->accessToken;

            return response()->json(['data' => $user, 'success' => $success], 200);
        } else {
            return response()->json(['error' => 'Unauthorised'], 401);
        }
    }
}

1 个答案:

答案 0 :(得分:2)

您可以使用let env = new docusign.EnvelopeDefinition(); .... // Request that the envelope be sent by setting |status| to "sent". // To request that the envelope be created as a draft, set to "created" env.status = 'sent'; 来做到这一点:

->only