如何从数组对象中获取特定项的值,如下所示

时间:2017-01-15 17:54:24

标签: php laravel laravel-5.2 laravel-5.3

ActivationToken {#194 ▼


#fillable: array:1 [▶]
  #connection: null
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  #perPage: 15
  +incrementing: true
  +timestamps: true
  #attributes: array:5 [▶]
  #original: array:5 [▼
    "token" => "h8diZf"
    "user_id" => 26
    "updated_at" => "2017-01-15 17:46:04"
    "created_at" => "2017-01-15 17:46:04"
    "id" => 26
  ]
  #relations: []
  #hidden: []
  #visible: []
  #appends: []
  #guarded: array:1 [▶]
  #dates: []
}

在这里,我想得到令牌的价值,即h8diZf。 该数组存储在$ token中。 那么,任何人都可以告诉我如何获得这个价值吗?

编辑:

这是用于设置令牌的代码,Activation是一个模型

protected function registered(Request $request, $user)
{
    Auth::logout();

    $token = $user->activationToken()->create([
        'token' => str_random(6),
    ]);

    Mail::to($user)->send(new SendActivationToken($token));
    dd($token);
     return redirect('/activate')->with('token', $token)->with('info', ' Please activate your account. We have sent you a code in your email, please fill it in the box below');
}

这是activationToken模型:

class ActivationToken extends Model
{
protected $fillable = ['token'];

public function getRouteKeyName()
{
    return 'token';
}

public function user()
{
    return $this->belongsTo(User::class);
}
}

0 个答案:

没有答案