简体   繁体   中英

Laravel Spark Token Visibility

I am trying to allow users to see their token. Laravek\\Spark\\Token looks partially like this:

<?php

namespace Laravel\Spark;

use Carbon\Carbon;
use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;

class Token extends Model
{

/**
 * The guarded attributes on the model.
 *
 * @var array
 */
protected $guarded = [];

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = [
    'token',
];

I am trying to remove token from being hidden. If I simply remove it from this core file, then when I update spark it is overridden. How do I change this value in code?

If I extend the token class, then I have to change other core files to use the extended class.

<?php

namespace App\Models;

use Laravel\Spark\Token;

class VisibleToken extends Token {

    protected $hidden = [];
}

Any insights are appreciated!

UPDATE:

I thought for sure this would work, but it doesn't. I still don't receive the token attribute.

      $userId = Auth::user()->id;
      $tokenModel = new Token();
      $tokenModel->setVisible(['token']);
      $tokenModel->setHidden([]);
      $tokens = $tokenModel->where('user_id', '=', $userId)->get();

I guess it would be done temporarily like this.

$model->setHidden(array $columns);

https://stackoverflow.com/a/24758855/55124

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM