0

I have Laravel 5.2 Backpacker admin for my new project and I need to make minor adjustments to the generated list view. Ie:

  1. 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;

  2. 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);
Community
  • 1
  • 1
Peon
  • 7,902
  • 7
  • 59
  • 100

1 Answers1

2

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!

tabacitu
  • 6,047
  • 1
  • 23
  • 37
  • Thank you, I did not know I can create custom field types so easily. Any idea, how to add style to the whole `` to highlight it? – Peon Dec 14 '16 at 16:12
  • Unfortunately, I think that would be pretty difficult, as Datatables.js interprets it and Backpack doesn't provide a way to easily do that... – tabacitu Dec 15 '16 at 11:29
  • You CAN however modify the list.blade.php file, where the TR is rendered. You can find it in your /resources/views/vendor/backpack/crud. If it's not there, you can copy it from the package in vendor, with the same name. Backpack will try to see if there's one in your resources folder. If not, it falls back to the one in the package. – tabacitu Dec 15 '16 at 11:30