【发布时间】:2015-09-03 13:20:17
【问题描述】:
我正在使用Auth::user() 获取有关当前登录用户的信息。现在我想扩展Auth::user() 提供的信息。具体用户的激活状态应该是可用的。
此信息存储在表activations 中的列state 中。
据我了解,Auth::user() 提供将从用户模型中检索到的内容。所以我应该在表users 和表activations 之间建立关系。 documentation 声明了 2 个可能性,都要求 activations 表有一个 foreign_key user_id。
我的表格布局没有涵盖这一点,我只是在 users 表格中引用了 actvtion_id。
是否有可能与我的表格布局建立关系,从而产生预期的结果,Auth::user() 为我提供激活状态?如果我该怎么做?
或者我是否必须按照文档中的建议切换表格布局?
在我的表格代码下方:
控制器:
class ProfileController extends Controller {
public function me()
{
return Auth::user( );
}
}
用户(迁移):
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('email')->unique();
$table->integer('activation_id')->unsigned();
$table->foreign('activation_id')->references( 'id' )->on( 'activations' );
//...
$table->timestamps();
});
激活(迁移):
Schema::create('activations', function(Blueprint $table)
{
$table->increments('id');
$table->string('activationStatus', 1)->nullable()->default('N');
// ...
$table->timestamps();
});
【问题讨论】:
标签: php authentication laravel-5 eloquent relationship