我有一个关于我正在从事的项目的简单问题 我需要在用户第一次登录时仅显示一次Modal Popup! 我创建了此代码,但仍无法正常工作
test.blade.php
@if ($first_time_login)
<h3>Welcome Popup</h3>
@else
<h3>Hey! ? Nothing to Show</h3>
@endif
TestController
public function Test()
{
if (Auth::user()->first_time_login) {
$first_time_login = true;
Auth::user()->first_time_login = 1;
Auth::user()->save();
} else {
$first_time_login = false;
}
return view(
'test',
['first_time_login' => $first_time_login]
);
}
2014_10_12_000000_create_users_table.php
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->nullable();
$table->string('email')->unique()->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password')->nullable();
$table->rememberToken()->nullable();
$table->timestamps();
$table->string('first_time_login')->default(false);
});
答案 0 :(得分:1)
我在您的代码中看到了一些东西。
首先,您将first_time_login
字段声明为字符串,它应该是布尔值,默认值为true
。像这样:
2014_10_12_000000_create_users_table.php
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->nullable();
$table->string('email')->unique()->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password')->nullable();
$table->rememberToken()->nullable();
$table->timestamps();
$table->boolean('first_time_login')->default(true);
});
另一件事,在检查它是否是首次登录后,将其设置为1
。这将使您的字段保持为true
。更改为:
TestController
public function Test()
{
if (Auth::user()->first_time_login) {
$first_time_login = true;
Auth::user()->first_time_login = false;
Auth::user()->save();
} else {
$first_time_login = false;
}
return view(
'test',
['first_time_login' => $first_time_login]
);
}
应该这样做。