0
我想通過循環中的'alpha'做一個簡單的組,用於詞彙表頁面,但不知道如何實現這一點。我的數據是laravel 4組集合/結果
阿爾法glossary_title
一個蘋果乙香蕉蘋果的另一!
GlossaryController.php
public function index() {
$glossary = Glossary::groupBy('alpha')->orderBy('glossary_title', 'asc')->get();
return View::make('glossary')->with('glossary', $glossary);
}
遷移
Schema::create('glossary', function(Blueprint $table)
{
// columns
$table->increments('id');
$table->string('glossary_title');
$table->text('glossary_desc')->nullable();
$table->char('alpha', 1);
$table->timestamps();
});
glossary.blade.php
@foreach($glossary as $glossary)
<li>{{ $glossary->glossary_title}} <br /> {{ $glossary->glossary_desc}}</li>
@endforeach