Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Route::
- =========
- Route::get('/rss.xml', 'RssController@index');
- Controller:: RssController.php
- =========
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Http\Requests;
- class RssController extends Controller
- {
- public function index()
- {
- $posts = \App\Post::orderBy('created_at','desc')->take(5)->get();
- //$articles = Article::all()->first();
- //$categories = Category::all()->first();
- //$questions = Question::all()->first();
- //$tags = Tag::all()->first();
- return response()->view('rss.index', [
- 'posts' => $posts,
- ])->header('Content-Type', 'text/xml');
- }
- }
- Views::==
- <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
- <rss version="2.0"
- xmlns:content="http://purl.org/rss/1.0/modules/content/">
- <channel>
- <title>News Publisher</title>
- <link>http://campustimes.press/rss.xml/</link>
- <description>
- Read our awesome news, every day.
- </description>
- <language>en-us</language>
- @foreach($posts as $post)
- <item>
- <title>{{htmlentities($post->title)}}</title>
- <description>{{htmlspecialchars(htmlentities($post->excerpt))}}></description>
- <link>{{ route('single.post', ['category' => $post->Category()->first()->slug, 'id' => $post->id, 'title' => make_slug($post->title)]) }}</link>
- </item>
- @endforeach
- </channel>
- </rss>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement