與Laravel 5.2和Laravel Collective一起工作。所以我有這個問題 - 我試圖用我的用戶的first_name
和last_name
進行下拉(選擇),但在我的用戶表first_name
和last_name
處於不同的行。我怎樣才能一起在一個下拉列表中顯示它們?從下拉列表中的一行中的兩行 - Laravel 5.2
這裏是我的控制器有:
'teachers'=>User::where('type','=','teacher')->lists('first_name', 'last_name','id'),
有了這個,我只看到first_name
。
並在視圖:
{!! Form::select('teacher_name', $teachers, null, ['class' => 'form-control']) !!}
表結構:
Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('username'); $table->string('password'); $table->string('first_name', 20); $table->string('last_name', 20); $table->integer('class_id') ->unsigned() ->nullable(); $table->enum('type', ['admin', 'teacher', 'student']); $table->rememberToken(); $table->timestamps();
人嗎?
你的意思是first_name和last_name在不同的行中是什麼意思?你可以在這裏發佈你的表格結構嗎? – Donkarnash
等待我將更新:) –
好的,你只能看到first_name,因爲它的工作原理應該如此。當你在{!! Form :: select()!!}中傳遞$ teachers數組時,它會將它填充爲選擇選項的鍵值對。因此,如果您使用devtools檢查select元素,您將能夠看到每個選項的last_name值。例如:如果要顯示first_name last_name並希望該值爲用戶的id,則必須相應地在控制器中構建教師陣列 –
Donkarnash