Reputation: 8030
I have Laravel 5.2 Backpacker admin for my new project and I need to make minor adjustments to the generated list view. Ie:
I have amount stored as cents in database, but would need to show as regular amount, so this would basically require to divide all values from amount
column by 100;
I have certain rows, that have the cancelled
date in them. I would like to set the row class to 'warning' for these.
So far I found only this complete override solution, but was wondering, if it could be done simpler in the crud controller.
I already can modify the header with this:
$this->crud->setColumnDetails('amount', ['label' => 'Total Amount']);
Is there such a simple option for data rows? Like:
$this->crud->setColumnData('amount', $this->crud->amount/100);
Upvotes: 0
Views: 1702
Reputation: 6223
1) I'd recommend using an accesor, say:
public function getAmountInDollarsAttribute($value)
{
return ($this->amount)/100;
}
You will then be able to add a column for that attribute, "amountInDollars".
2) An easy way to achieve something similar would be to create a custom column. Inside it you will be able to show a warning/success label, which will make that row stand out. Something like:
<td>
@if ($entry->cancelled_date)
<span class="label label-danger">Cancelled</span>
@else
<span class="label label-default">Not cancelled</span>
@endif
</td>
Hope it helps. Cheers!
Upvotes: 2