繁体   English   中英

仅在用户首次登录时显示弹出窗口(Laravel)

[英]show pop up only first time user login (Laravel)

我有一个关于我正在处理的项目的简单问题,当用户第一次登录时,我需要显示一个模态弹出窗口,不再只有一次!!! 我创建了这段代码,但它仍然无法正常工作

test.blade.php

@if ($first_time_login)
   <h3>Welcome Popup</h3>
@else 
  <h3>Hey! 🖐 Nothing to Show</h3>
@endif

测试控制器

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);
    });

我在你的代码上看到了一些东西。

首先,您将first_time_login字段声明为字符串,它应该是 boolean ,默认值为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不变。 将其更改为:

测试控制器

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]
    ); 
}

那应该这样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM