Advertisement
rodro1

Untitled

Nov 5th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Route::
  2. =========
  3. Route::get('/rss.xml', 'RssController@index');
  4.  
  5. Controller:: RssController.php
  6. =========
  7. <?php
  8.  
  9. namespace App\Http\Controllers;
  10.  
  11. use Illuminate\Http\Request;
  12.  
  13. use App\Http\Requests;
  14.  
  15. class RssController extends Controller
  16. {
  17. public function index()
  18. {
  19. $posts = \App\Post::orderBy('created_at','desc')->take(5)->get();
  20. //$articles = Article::all()->first();
  21. //$categories = Category::all()->first();
  22. //$questions = Question::all()->first();
  23. //$tags = Tag::all()->first();
  24.  
  25. return response()->view('rss.index', [
  26. 'posts' => $posts,
  27. ])->header('Content-Type', 'text/xml');
  28. }
  29. }
  30.  
  31. Views::==
  32.  
  33. <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
  34.  
  35. <rss version="2.0"
  36. xmlns:content="http://purl.org/rss/1.0/modules/content/">
  37. <channel>
  38. <title>News Publisher</title>
  39. <link>http://campustimes.press/rss.xml/</link>
  40. <description>
  41. Read our awesome news, every day.
  42. </description>
  43. <language>en-us</language>
  44.  
  45. @foreach($posts as $post)
  46. <item>
  47. <title>{{htmlentities($post->title)}}</title>
  48. <description>{{htmlspecialchars(htmlentities($post->excerpt))}}></description>
  49. <link>{{ route('single.post', ['category' => $post->Category()->first()->slug, 'id' => $post->id, 'title' => make_slug($post->title)]) }}</link>
  50. </item>
  51. @endforeach
  52.  
  53. </channel>
  54. </rss>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement