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

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

在laravel中,如何在視圖中使用@if語句來驗證數據庫條件,以便它根據條件隱藏/顯示一些內容

在laravel中,如何在視圖中使用@if語句來驗證數據庫條件,以便它根據條件隱藏/顯示一些內容

PHP
HUWWW 2022-08-05 15:34:07
這是 home.blade.php 文件   @foreach($userview as $userview){                    @if($userview = [{"role_code": "auv_recommend"}]){                        <center>                            <div class="box">                                <div class="dropdown">                                    <button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" data-submenu aria-expanded="false">AUV</button>                                    <div class="dropright dropdown-menu" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(14px, 60px, 0px);">                                        <button class="dropdown-item" type="button"><a tabindex=" -1" href="create">CREATE</a></button>                                            <button class="dropdown-item dropdown-toggle test1" type="button" data-toggle="dropdown">VIEW</button>                                            <div class="dropdown-menu dropright">                                                <button class="dropdown-item" type="button"><a tabindex="-1" href="pendinglistSH">Awaiting Approval</a></button>                                                <button class="dropdown-item" type="button"><a tabindex=" -1" href="reports">Reports</a></button>                                            </div>                                        </div>                                </div>                            </div>                            </center>}這是用于返回作為獨立身份驗證創建的主頁視圖的控制器<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;use Illuminate\Support\Facades\Session;class HomeController extends Controller{    /**     * Create a new controller instance.     *     * @return void     */    public function __construct()    {        $this->middleware('auth');    }另外,我如何僅在不返回數組的情況下獲取列值,以便我可以使用它來檢查我的條件,我嘗試將變量$userview插入會話中,以便我可以將其轉到另一個控制器并嘗試從主控制器調用變量,但它失敗了
查看完整描述

1 回答

?
青春有我

TA貢獻1784條經驗 獲得超8個贊

要回答第一個問題,您可以在負責提供視圖的方法中獲取所需的數據。例如,如果這是您的主頁,那將是.index()


例:


public function index(){


   $userview = Session::get('userview');


   // Example data

   $yourData = DB::table('users')->where('name', 'John')->first();


   // Pass an array as second argument to view to pass more data, or you 

   // can chain ->with calls

   return view('greetings', ['userview' => $userview, 'yourdata' => $user]);

}

然后,您可以在視圖中同時使用和。userviewyourdataindex


查看完整回答
反對 回復 2022-08-05
  • 1 回答
  • 0 關注
  • 121 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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