Git Product home page Git Product logo

feeds's Introduction

Laravel 5 Feeds

Latest Stable Version SensioLabsInsight License

Total Downloads Monthly Downloads Daily Downloads

A simple Laravel 5 service provider for including the SimplePie library.

Installation

The Laravel 5 Feeds Service Provider can be installed via Composer by requiring the willvincent/feeds package in your project's composer.json.

{
    "require": {
        "threebenji/feeds": "1.1.*"
    }
}

Configuration

If you're using Laravel 5.5 you may skip the next step.

To use the Feeds Service Provider, you must register the provider when bootstrapping your Laravel application.

Find the providers key in your config/app.php and register the Service Provider.

    'providers' => [
        // ...
        threebenji\Feeds\FeedsServiceProvider::class,
    ],

Find the aliases key in your config/app.php and register the Facade.

    'aliases' => [
        // ...
        'Feeds'    => threebenji\Feeds\Facades\FeedsFacade::class,
    ],

Usage

Run php artisan vendor:publish --provider="threebenji\Feeds\FeedsServiceProvider" to publish the default config file, edit caching setting withing the resulting config/feeds.php file as desired.

See SimplePie Documentation for full API usage documentation.

The make() accepts 3 paramaters, the first parameter is an array of feed URLs, the second parameter is the max number of items to be returned per feed, and while the third parameter is a boolean which you can set to force to read unless content type not a valid RSS.

$feed = Feeds::make('http://feed/url/goes/here');
Note: In Laravel 5, Facades must either be prefixed with a backslash, or brought into scope with a use [facadeName] declaration.

Example controller method, and it's related view:

Controller:

  public function demo() {
    $feed = Feeds::make('http://blog.case.edu/news/feed.atom');
    $data = array(
      'title'     => $feed->get_title(),
      'permalink' => $feed->get_permalink(),
      'items'     => $feed->get_items(),
    );

    return View::make('feed', $data);
  }

or Force to read unless content type not a valid RSS

  public function demo() {
    $feed = Feeds::make('http://blog.case.edu/news/feed.atom', true); // if RSS Feed has invalid mime types, force to read
    $data = array(
      'title'     => $feed->get_title(),
      'permalink' => $feed->get_permalink(),
      'items'     => $feed->get_items(),
    );

    return View::make('feed', $data);
  }

Multifeeds example controller method, and it's related view:

Controller:

  public function demo() {
    $feed = Feeds::make([
        'http://blog.case.edu/news/feed.atom',
        'http://tutorialslodge.com/feed'
    ], 5);
    $data = array(
      'title'     => $feed->get_title(),
      'permalink' => $feed->get_permalink(),
      'items'     => $feed->get_items(),
    );

    return View::make('feed', $data);
  }

or Force to read unless content type not a valid RSS

  public function demo() {
        $feed = Feeds::make(['http://blog.case.edu/news/feed.atom',
        'http://tutorialslodge.com/feed'
    ], 5, true); // if RSS Feed has invalid mime types, force to read
    $data = array(
      'title'     => $feed->get_title(),
      'permalink' => $feed->get_permalink(),
      'items'     => $feed->get_items(),
    );

    return View::make('feed', $data);
  }

View:

@extends('app')

@section('content')
  <div class="header">
    <h1><a href="{{ $permalink }}">{{ $title }}</a></h1>
  </div>

  @foreach ($items as $item)
    <div class="item">
      <h2><a href="{{ $item->get_permalink() }}">{{ $item->get_title() }}</a></h2>
      <p>{{ $item->get_description() }}</p>
      <p><small>Posted on {{ $item->get_date('j F Y | g:i a') }}</small></p>
    </div>
  @endforeach
@endsection

feeds's People

Contributors

willvincent avatar yantianlei avatar koenhoeijmakers avatar ammezie avatar xvlady avatar ecodrutz avatar daniesy avatar yamenarahman avatar uitlaber avatar barisbora avatar ahmedfawzy avatar haegemon avatar jonasva avatar blueclock avatar gavro avatar christianesperar avatar arthurkirkosa avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.