You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
846 B
PHTML

<?php
namespace App\Exports;
use App\Models\Booking;
use Carbon\Carbon;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromView;
class BookingsExport implements FromView
{
use Exportable;
/**
* @return \Illuminate\Support\Collection
*/
public function view(): View
{
$query = Booking::query()->orderBy('departure', 'ASC');
if (request('ids')) {
$bookingIds = request('ids');
$query->whereIn('id', $bookingIds);
}
$bookings = $query->get()->map(function ($item, $key) {
$item->departure = Carbon::parse($item->departure)->format('Y-m-d');
return $item;
});
return view('exports.bookings_export', [
'bookings' => $bookings,
]);
}
}