在laravel auth中设置自定义用户详细信息

在laravel auth中设置自定义用户详细信息,laravel,authentication,smf,Laravel,Authentication,Smf,我有一个smf论坛,在那里使用数据库中的smf_成员表。有如下字段: array(32) { ["groups"]=> array(2) { [0]=> int(1) [1]=> int(25) } ["possibly_robot"]=> bool(false) ["id"]=> string(2) "28" ["username"]=> string(7) "Milan95" ["na

我有一个smf论坛,在那里使用数据库中的smf_成员表。有如下字段:

array(32) {
  ["groups"]=>
  array(2) {
    [0]=>
    int(1)
    [1]=>
    int(25)
  }
  ["possibly_robot"]=>
  bool(false)
  ["id"]=>
  string(2) "28"
  ["username"]=>
  string(7) "Milan95"
  ["name"]=>
  string(7) "Milan95"
  ["email"]=>
  string(16) "******"
  ["passwd"]=>
  string(40) "******"
  ["language"]=>
  string(18) "serbian_latin-utf8"
  ["is_guest"]=>
  &bool(false)
  ["is_admin"]=>
  &bool(true)
  ["theme"]=>
  string(1) "7"
  ["last_login"]=>
  string(10) "1576930811"
}
此外,我有拉威尔模型“用户”

但我只能在打电话时获取该信息: 用户::查找($id);然后是来自smf_成员的数据

我找不到任何方法将活动会话和数据从中放入用户模型和字段

 global $user_info;
 var_dump($user_info);
我从第一个“代码”中获取数据


谢谢,请帮助:)

您可以使用雄辩的访问者。将您的模型更新为:

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use Notifiable;
    use HasRoles;

    protected $fillable = [
        'real_name', 'email', 'password',
    ];
    protected $hidden = [
        'password', 'remember_token',
    ];

    // add this line if you're using api
    protected $appends = ['smf_info'];


    protected $table = 'smf_members';
    protected $primaryKey = 'id_member';
    public $timestamps = false;

    // add this block
    public function getSmfInfoAttribute()
    {
      return // your logic to find current user smf info
    }
}

然后您可以通过
User::find($id)->smf\u info

访问该属性,为什么要声明全局用户?如果您想访问刚刚使用的当前登录用户
Auth::user()
Auth()->user()
我使用全局$user\u info从SMF SSI文件获取数据,在这里我将获取SMF会话。我不想在laravel中使用两个登录/注册表单。要替换Auth::user()和smf数据中的数据。只需将smf数据放入laravel auth即可。XD您可能希望对此进行调查,但我不能使用laravel权限和其他包。使用模型是实现这一点的最简单和最好的方法,但我只想将用户设置为当前smf用户id。我的意思是获取数据并使用这个自定义函数。非常感谢你。
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use Notifiable;
    use HasRoles;

    protected $fillable = [
        'real_name', 'email', 'password',
    ];
    protected $hidden = [
        'password', 'remember_token',
    ];

    // add this line if you're using api
    protected $appends = ['smf_info'];


    protected $table = 'smf_members';
    protected $primaryKey = 'id_member';
    public $timestamps = false;

    // add this block
    public function getSmfInfoAttribute()
    {
      return // your logic to find current user smf info
    }
}