亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

僅在用戶首次登錄時顯示彈出窗口 (Laravel)

僅在用戶首次登錄時顯示彈出窗口 (Laravel)

PHP
慕田峪7331174 2022-12-11 16:21:09
我有一個關于我正在處理的項目的簡單問題我需要在用戶第一次登錄時顯示一次模態彈出窗口,而不僅僅是一次?。?! 我創建了這段代碼,但它仍然無法正常工作測試.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);    });
查看完整描述

1 回答

?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

我在你的代碼中看到了一些東西。


首先,您將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. 將其更改為:


測試控制器


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]

    ); 

}

應該這樣做。


查看完整回答
反對 回復 2022-12-11
  • 1 回答
  • 0 關注
  • 143 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號