Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion app/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\View;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;

class Event extends Model
class Event extends Model implements Feedable
{
use SoftDeletes;

Expand All @@ -32,4 +35,28 @@ public static function pending()
->orderBy('created_at')
->get();
}

/**
* @return array|\Spatie\Feed\FeedItem
*/
public function toFeedItem()
{
$summary = View::make('feedItem', ['event' => $this])->render();

return FeedItem::create()
->id($this->id)
->title($this->title)
->author('')
->summary($summary)
->updated($this->updated_at)
->link($this->url);
}

public static function getFeedItems()
{
return self::where('starts_at', '>', Carbon::now())
->where('approved', 1)
->orderBy('created_at', 'desc')
->get();
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"laravel/framework": "5.6.*",
"laravel/tinker": "^1.0",
"nothingworks/blade-svg": "^0.2.2",
"spatie/laravel-feed": "^2.1",
"uploadcare/uploadcare-php": "^2.2"
},
"require-dev": {
Expand Down
73 changes: 72 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions config/feed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

return [

'feeds' => [
'news' => [
/*
* Here you can specify which class and method will return
* the items that should appear in the feed. For example:
* '\App\Model@getAllFeedItems'
*/
'items' => 'App\Event@getFeedItems',

/*
* The feed will be available on this url.
*/
'url' => '/feed',

'title' => 'New events at ' . config('app.name', 'Laravel'),

/*
* Custom view for the items.
*
* Defaults to feed::feed if not present.
*/
'view' => 'feed::feed',
],
],

];
16 changes: 16 additions & 0 deletions resources/views/feedItem.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@if ($event->image)
<img src="{{ $event->fullimage }}" />
<br />
@endif
<p>
{!! nl2br($event->description) !!}
</p>
<p>
Location: {{ $event->location }}
</p>
<p>
Price: {{ $event->price }}
</p>
<p>
Date: {{ $event->starts_at->format("M d, Y") }}
</p>
1 change: 1 addition & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<link rel="stylesheet" type="text/css" href="https://cloud.typography.com/6559534/6834192/css/fonts.css" />
<link href="{{ mix('/css/app.css') }}" rel="stylesheet">
@yield('header-scripts')
@include('feed::links')
</head>
<body>
<div id="app">
Expand Down
29 changes: 29 additions & 0 deletions resources/views/vendor/feed/feed.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?=
/* Using an echo tag here so the `<? ... ?>` won't get parsed as short tags */
'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL
?>
<feed xmlns="http://www.w3.org/2005/Atom">
@foreach($meta as $key => $metaItem)
@if($key === 'link')
<{{ $key }} href="{{ url($metaItem) }}"></{{ $key }}>
@elseif($key === 'title')
<{{ $key }}><![CDATA[{{ $metaItem }}]]></{{ $key }}>
@else
<{{ $key }}>{{ $metaItem }}</{{ $key }}>
@endif
@endforeach
@foreach($items as $item)
<entry>
<title><![CDATA[{{ $item->title }}]]></title>
<link rel="alternate" href="{{ url($item->link) }}" />
<id>{{ url($item->id) }}</id>
<author>
<name> <![CDATA[{{ $item->author }}]]></name>
</author>
<summary type="html">
<![CDATA[{!! $item->summary !!}]]>
</summary>
<updated>{{ $item->updated->toAtomString() }}</updated>
</entry>
@endforeach
</feed>
3 changes: 3 additions & 0 deletions resources/views/vendor/feed/links.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@foreach($feeds as $name => $title)
<link rel="alternate" type="application/rss+xml" href="{{ route("feeds.{$name}") }}" title="{{ $title }}">
@endforeach
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
Route::post('/submit', 'SubmitController@store');
Route::get('/cp', function(){ return redirect('/cp/manage'); });
Route::resource('/cp/manage', 'ManageEventsController');
Route::feeds();
Auth::routes();