Closed rizkyblackhat closed 3 weeks ago
class LicenseCartDataTable extends DataTable
{
/**
* Build the DataTable class.
*/
public function dataTable(): CollectionDataTable
{
$collection = $this->query();
return (new CollectionDataTable($collection))
->editColumn('price', function ($cart) {
$product = Product::find($cart['product_id']);
$price = (Auth::user()->role === 'member' ? $product->sell_price : $product->base_price) * $cart['duration'];
return $price;
})
->addColumn('product_name', function ($cart) {
$product = Product::find($cart['product_id']);
return $product->name;
})
->addColumn('action', function($cart) {
$delete = route('orders.license.order.cart.delete', $cart['id']);
return "
<a href=\"#\" class=\"btn btn-icon btn-danger\" onclick=\"confirmDelete('$delete')\"><i class=\"fas fa-times\"></i></a>
";
});
}
/**
* Get the query source of dataTable.
*/
public function query()
{
$collection = collect(Session::get('cart_' . Auth::id(), []));
return $collection;
}
Summary of problem or feature request
How can I use an array as a data source, similar to how we use ORM models?
Code snippet of problem
System details