:::

9-2 在視圖中取得使用者編號

  1. 由於建立測驗時,我們需要紀錄建立者的編號,所以,我們修改\專案\resources\views\exam\create.blade.php視圖,加入隱藏欄位,並用Auth::id()取得目前登入者的使用者編號:
    {{ bs()->openForm('post', '/exam') }}
        {{ bs()->formGroup()
                ->label('測驗標題', false, 'text-sm-right')
                ->control(bs()->text('title')->placeholder('請填入測驗標題'))
                ->showAsRow() }}
    
        {{ bs()->formGroup()
                ->label('測驗狀態', false, 'text-sm-right')
                ->control(bs()->radioGroup('enable', [1 => '啟用', 0 => '關閉'])
                            ->selectedOption(1)
                            ->inline())
                ->showAsRow() }}
        {{ bs()->hidden('user_id', Auth::id()) }}
        {{ bs()->formGroup()
                ->label('')
                ->control(bs()->submit('建立測驗'))
                ->showAsRow() }}
    {{ bs()->closeForm() }}
  2. Auth::id()是用來取得目前登入者的編號,詳細用法可參考:https://laravel-china.org/docs/laravel/5.6/authentication/1379#retrieving-the-authenticated-user

到GitHub觀看此單元程式異動  


:::

書籍目錄

展開 | 闔起

http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D37%26tbdsn%3D1178

計數器

今天: 4869486948694869
昨天: 3438343834383438
總計: 7395198739519873951987395198739519873951987395198