2017-09-23 2 views
0

이미 앱 폴더에있는 사용자 모델을 사용하고 싶습니다. 하지만 그것은 단지 Authenticatable 확장하고있는 모델로 확장 할 수없는 것 같아요 클래스 나는 다른 클래스에 대한 링크로 그것을 사용하려는 사용자처럼 단 한명의 직원이 있습니다. 이미 Authenticatable에서 확장 한 사용자 모델을 재활용하려면 어떻게해야합니까? 도움말 :Laravel 5.5 관계에 대한 사용자 모델 사용

이에 대한

덕분으로 인증

<?php 

namespace App; 

use Illuminate\Notifications\Notifiable; 
use Illuminate\Foundation\Auth\User as Authenticatable; 

class User extends Authenticatable 
{ 
    use Notifiable; 

    /** 
    * The attributes that are mass assignable. 
    * 
    * @var array 
    */ 
    protected $fillable = [ 
     'name', 'email', 'password', 
    ]; 

    /** 
    * The attributes that should be hidden for arrays. 
    * 
    * @var array 
    */ 
    protected $hidden = [ 
     'password', 'remember_token', 
    ]; 

    public function employee() 
    { 
     return $this->belongsTo('App\Employee'); 
    } 
} 

를 확장하는 사용자 모델입니다 그리고 이것은 이미 모델 클래스 상속 직원 모델

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 

class Employee extends Model 
{ 

// protected $table = "positions"; 

    // public function position() 
    // { 
    // return $this->hasMany('App\Position'); 
    // } 

    protected $table = "employees"; 

    public function employee() 
    { 
     return $this->hasOne('App\User'); 
    } 
} 
+0

또한 사용자 모델은 모델을 확장하지만 일부 상속을받습니다. 다른 모델처럼 모든 것을 할 수 있습니다. –

+0

'Illuminate \ Foundation \ Auth \ User를'인증 가능 '으로 사용하십시오. –

+0

@MortezaRajabi 그래서 사용자 클래스가 이미 모델 클래스를 상속 받았음을 의미합니까? – unknown

답변

2

입니다. Illuminate\Foundation\Auth\User을 따르는 경우 마침내 Model 클래스에서 상속되었음을 알 수 있습니다. 따라서 사용자 모델에는 다른 모델과 동일한 기능이 있습니다.

관련 문제