0
既にアプリケーションフォルダにあるユーザーモデルを使用したいと思います。しかし、それは認証のみを拡張し、モデルによって拡張することはできませんクラス私は、ユーザーが1人の従業員しか持たないように、他のクラスへのリンクとしてそれを使用したいと思います。 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');
}
}
を拡張し、これはこれは、すでにModelクラス継承
<?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');
}
}
ユーザーモデルもモデルを継承しますが、継承もあります。他のモデルのようにすべてを行うことができます。 –
「Illuminate \ Foundation \ Auth \ Userを認証可能として使用する」に従ってください。 –
@MortezaRajabiなので、ユーザークラスが既にモデルクラスを継承しているということですか? – unknown