修改Laravel背包客CRUD列表视图
Modify Laravel Backpacker CRUD list view
我的新项目有 Laravel 5.2 Backpacker 管理员,我需要对生成的列表视图进行微调。即:
我在数据库中将金额存储为美分,但需要显示为常规金额,因此这基本上需要将 amount
列中的所有值除以 100;
我有某些行,其中包含 cancelled
日期。对于这些,我想将行 class 设置为 'warning'。
到目前为止我只找到 完整的覆盖解决方案,但想知道是否可以在 crud 控制器中更简单地完成它。
我已经可以用这个修改 header:
$this->crud->setColumnDetails('amount', ['label' => 'Total Amount']);
数据行有这么简单的选项吗?喜欢:
$this->crud->setColumnData('amount', $this->crud->amount/100);
1) 我建议使用 an accesor,比如说:
public function getAmountInDollarsAttribute($value)
{
return ($this->amount)/100;
}
然后您将能够 add a column 该属性,"amountInDollars"。
2) 实现类似功能的简单方法是 create a custom column。在其中,您将能够显示 warning/success 标签,这将使该行脱颖而出。类似于:
<td>
@if ($entry->cancelled_date)
<span class="label label-danger">Cancelled</span>
@else
<span class="label label-default">Not cancelled</span>
@endif
</td>
希望对您有所帮助。干杯!
我的新项目有 Laravel 5.2 Backpacker 管理员,我需要对生成的列表视图进行微调。即:
我在数据库中将金额存储为美分,但需要显示为常规金额,因此这基本上需要将
amount
列中的所有值除以 100;我有某些行,其中包含
cancelled
日期。对于这些,我想将行 class 设置为 'warning'。
到目前为止我只找到
我已经可以用这个修改 header:
$this->crud->setColumnDetails('amount', ['label' => 'Total Amount']);
数据行有这么简单的选项吗?喜欢:
$this->crud->setColumnData('amount', $this->crud->amount/100);
1) 我建议使用 an accesor,比如说:
public function getAmountInDollarsAttribute($value)
{
return ($this->amount)/100;
}
然后您将能够 add a column 该属性,"amountInDollars"。
2) 实现类似功能的简单方法是 create a custom column。在其中,您将能够显示 warning/success 标签,这将使该行脱颖而出。类似于:
<td>
@if ($entry->cancelled_date)
<span class="label label-danger">Cancelled</span>
@else
<span class="label label-default">Not cancelled</span>
@endif
</td>
希望对您有所帮助。干杯!