代码之家  ›  专栏  ›  技术社区  ›  anaximander

Laravel 5访问会话用户

  •  0
  • anaximander  · 技术社区  · 7 年前

    $testing = $request->user();
    
    dd($testing);
    

    用户对象:

    User {#596 ▼
      #table: "users"
      +primaryKey: "id"
      #fillable: array:3 [▶]
      #hidden: array:2 [▶]
      #connection: "mysql"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:9 [▶]
      #original: array:9 [▶]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #visible: []
      #guarded: array:1 [▶]
      #rememberTokenName: "remember_token"
    }
    

    我如何访问例如 #attributes

    1 回复  |  直到 7 年前
        1
  •  2
  •   Remul    7 年前

    可以通过以下方式访问属性:

    magic method __get() :

    $request->user()->yourAttribute;
    

    getAttribute 直接法:

    $request->user()->getAttribute('yourAttribute');
    
    推荐文章