:::
9-2 在視圖中取得使用者編號
- 由於建立測驗時,我們需要紀錄建立者的編號,所以,我們修改
\專案\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() }} Auth::id()是用來取得目前登入者的編號,詳細用法可參考:https://laravel-china.org/docs/laravel/5.6/authentication/1379#retrieving-the-authenticated-user
9-1 修改路由改用控制器
