Files
einundzwanzig-portal/app/Http/Controllers/DownloadBitcoinEventCalendar.php
Shift 5776b01d15 Apply Laravel coding style
Shift automatically applies the Laravel coding style - which uses the PSR-12 coding style as a base with some minor additions.

You may customize the code style applied by configuring [Pint](https://laravel.com/docs/pint), [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer), or [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for your project root.

For more information on customizing the code style applied by Shift, [watch this short video](https://laravelshift.com/videos/shift-code-style).
2023-02-19 18:05:16 +01:00

47 lines
1.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\BitcoinEvent;
use Illuminate\Http\Request;
use Spatie\IcalendarGenerator\Components\Calendar;
use Spatie\IcalendarGenerator\Components\Event;
class DownloadBitcoinEventCalendar extends Controller
{
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function __invoke(Request $request)
{
$events = BitcoinEvent::query()
->with([
'venue.city.country',
])
->get();
$entries = [];
foreach ($events as $event) {
$entries[] = Event::create()
->name($event->title)
->uniqueIdentifier(str($event->title)->slug().$event->id)
->address($event->venue->name.', '.$event->venue->street.', '.$event->venue->city->name.', '.$event->venue->city->country->name)
->description(str_replace(["\r", "\n"], '', $event->description).' Link: '.$event->link)
->image($event->getFirstMediaUrl('logo'))
->startsAt($event->from)
->endsAt($event->to);
}
$calendar = Calendar::create()
->name(__('Bitcoin Events'))
->refreshInterval(5)
->event($entries);
return response($calendar->get())
->header('Content-Type', 'text/calendar; charset=utf-8');
}
}