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