Php 仅在用户首次登录时显示弹出窗口(Laravel)
我有一个关于我正在做的项目的简单问题 当用户第一次登录时,我需要显示一次模式弹出窗口,不再只显示一次强> 我创建了这段代码,但它仍然不起作用 test.blade.phpPhp 仅在用户首次登录时显示弹出窗口(Laravel),php,laravel,Php,Laravel,我有一个关于我正在做的项目的简单问题 当用户第一次登录时,我需要显示一次模式弹出窗口,不再只显示一次 我创建了这段代码,但它仍然不起作用 test.blade.php @if ($first_time_login) <h3>Welcome Popup</h3> @else <h3>Hey! I see a few things on your code. Firstly you are declaring the first_time_login
@if ($first_time_login)
<h3>Welcome Popup</h3>
@else
<h3>Hey! I see a few things on your code.
Firstly you are declaring the first_time_login
field as a string, it should be boolean with default value of true
. Like this:
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);
});
@if($first\u time\u login)
欢迎弹出窗口
@否则
嘿 我在你的代码中看到了一些东西
首先,将first\u time\u login
字段声明为字符串,它应该是布尔值,默认值为true
。像这样:
2014\u10\u12\u000000\u创建用户\u表格.php
Schema::create('users',函数(Blueprint$表){
$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\u time\u login')->默认值(true);
});
另一件事,在检查是否是首次登录后,您将其设置为1
。这将使您的字段保持为true
。将其更改为:
TestController
公共功能测试()
{
if(Auth::user()->首次登录){
$first\u time\u login=true;
Auth::user()->first\u time\u login=false;
Auth::user()->save();
}否则{
$first\u time\u login=false;
}
返回视图(
"测试",,
['first\u time\u login'=>$first\u time\u login]
);
}
应该可以了。你能提供更多细节吗?出了什么问题?消息是否显示?用户记录正在更新?你能重写整个源代码吗?我现在不知道问题在哪里。我用完整的代码更新了我的答案。我还忘了提到第一次登录的默认值应该是真的。你说的“不工作”是什么意思?你试过调试这个问题吗?