:::
8-2 建立發布測驗的表單
- 先來製作發佈測驗的前端界面
- 修改或建立
/專案/resources/views/exam/create.blade.php,簡易版可以這樣寫:@extends('layouts.app') @section('content') <h1>{{ __('Create Exam') }}</h1> @can('建立測驗') {{ bs()->openForm('post', '/exam') }} {{ bs()->text('title')->placeholder('請填入測驗標題') }} {{ bs()->radioGroup('enable', [1 => '啟用', 0 => '關閉']) ->selectedOption(1) ->inline() }} {{ bs()->submit('建立測驗') }} {{ bs()->closeForm() }} @else @component('bs::alert', ['type' => 'danger']) @slot('heading') 無建立測驗的權限 @endslot @endcomponent @endcan @endsection -
先用
@can('建立測驗')來判斷有無權限,若有,就製作表單。若無,則進入@else顯示警告畫面。

-
{{ bs()->openForm('post', '/exam') }}是用來產生表單,以{{ bs()->closeForm() }}做結尾,裡面的設定說明如下:-
回顧一下用來儲存的路由:動作是post,路徑是
/exam,別名是exam.store,詳情請看這裡。 -
用
url('/exam')來設定表單欲傳送的位址,因為是用post方式傳遞,所以路徑直接指向測驗的路徑即/exam即可,不需要指定/exam/store。
-
- 簡易版的看起來像這樣

- 可以加入表單群組,做成水平表單
@extends('layouts.app') @section('content') <h1>{{ __('Create Exam') }}</h1> @can('建立測驗') {{ 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()->formGroup() ->label('') ->control(bs()->submit('建立測驗')) ->showAsRow() }} {{ bs()->closeForm() }} @else @component('bs::alert', ['type' => 'danger']) @slot('heading') 無建立測驗的權限 @endslot @endcomponent @endcan @endsection - 看起來像這樣:

8-1 安裝marvinlabs/laravel-html-bootstrap-4套件
