Skip to content

Commit

Permalink
*course 34
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahdi Ebrahimi committed Jan 21, 2018
1 parent 8f638f6 commit c4615b6
Show file tree
Hide file tree
Showing 27 changed files with 7,691 additions and 4,974 deletions.
5 changes: 5 additions & 0 deletions app/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}

public function user()
{
return $this->belongsTo(User::class);
}
}
25 changes: 25 additions & 0 deletions app/Http/Controllers/FeedController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Article;

class FeedController extends Controller {

public function articles() {

$feed = app()->make('feed');

$feed->setCache(1, 'laravel.feed.article');

if (!$feed->isCached()) {
$articles = Article::latest()->take(10)->get();
foreach ($articles as $article)
$feed->add($article->title, $article->user->name, url($article->slug), $article->created_at, strip_tags ($article->description), strip_tags ($article->body));
}

return $feed->render('rss');
}

}
31 changes: 31 additions & 0 deletions app/Http/Controllers/SitemapController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Routing\Controller;

class SitemapController extends Controller {

public function index() {
$sitemap = app()->make('sitemap');
$sitemap->setCache('laravel.sitemap', 30);
if (!$sitemap->isCached())
$sitemap->add(url('sitemap-articles'), '2012-08-25T20:10:00+02:00', '0.5', 'daily');
return $sitemap->render();
}

public function articles() {
$sitemap = app()->make('sitemap');
$sitemap->setCache('laravel.sitemap.articles', 30);

if (!$sitemap->isCached()) {

$articles = \App\Article::latest()->get();
foreach ($articles as $article)
$sitemap->add(url($article->path()), '2012-08-25T20:10:00+02:00', '0.5', 'Weekly');
}

return $sitemap->render();
}

}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"morilog/jalali": "^2.2",
"predis/predis": "^1.1",
"pusher/pusher-php-server": "^2.6",
"roumen/feed": "2.10.*",
"roumen/sitemap": "2.6.*",
"uxweb/sweet-alert": "^1.4"
},
"require-dev": {
Expand Down
Loading

0 comments on commit c4615b6

Please sign in to comment.