HyanCat / larss by HyanCat

RSS builder for Laravel 5
557
3
3
Package Data
Maintainer Username: HyanCat
Maintainer Contact: hyancat@live.cn (HyanCat)
Package Create Date: 2015-05-15
Package Last Update: 2016-10-30
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:08:57
Package Statistics
Total Downloads: 557
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 3
Total Watchers: 3
Total Forks: 0
Total Open Issues: 0

larss

RSS builder for Laravel 5

Installation

  1. Pull down the package with composer:

     composer require hyancat/larss
    
  2. Add the service provider to your providers array in app/config/app.php file.

     'Hyancat\Larss\LarssServiceProvider'
    
  3. At last, add the alias to the alias array in app/config/app.php file.

     'RSS'		=> 'Hyancat\Larss\LarssFacade',
    

Usage

Usage with Cache:


$rss = \RSS::make();
if (! $rss->caching(10)) {

	// make channel.
	$rss->channel([
		'title'       => 'title',
		'description' => 'description',
		'link'        => 'http://www.xxx.yyy',
	])->withImage([
		'url'   => 'http://www.xxx.yyy/logo.png',
	  	'title' => 'title',
	  	'link'  => 'http://www.xxx.yyy',
	]);

	// gen posts data ......
	foreach ($posts as $post) {
		$rss->item([
			'title'             => $post->title,
			'description|cdata' => $post->body,
			'link'              => $post->url,
			// ......
		]);
	}
}

// If you want to save the rss data to file.
$rss->save('rss.xml');

// Or just make a response to the http request.
return \Response::make($rss->render(), 200, ['Content-Type' => 'text/xml']);

Usage without Cache:


// make with channel.
$rss = \RSS::make()->channel([
	'title'       => 'title',
	'description' => 'description',
	'link'        => 'http://www.xxx.yyy',
	// ......
])->withImage([
	'url'   => 'http://www.xxx.yyy/logo.png',
	'title' => 'title',
	'link'  => 'http://www.xxx.yyy',
]);

// gen posts data ......
foreach ($posts as $post) {
	$rss->item([
		'title'             => $post->title,
		'description|cdata' => $post->body,
		'link'              => $post->url,
		// ......
	]);
}

return ...;