0

I am trying to allow users to see their tokens. Laravel\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 the 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();
AWS PS
  • 4,420
  • 1
  • 9
  • 22
Bryan
  • 17,201
  • 24
  • 97
  • 123

1 Answers1

0

I guess it would be done temporarily like this.

$model->setHidden(array $columns);

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

Bryan
  • 17,201
  • 24
  • 97
  • 123